hdu1160 LIS
来源:互联网 发布:报刊制作软件coreldraw 编辑:程序博客网 时间:2024/06/01 08:01
题目链接:点击打开链接
题意:找到一种最长序列,满足老鼠的体重严格递增,速度严格递减。输出其中一种路径即可。
排序之后按LIS做就行。
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn=1e3+10;const int INF=0x3f3f3f3f;typedef struct mice{ int index; int w,v;} mice;mice a[maxn];int out[maxn],d[maxn];bool cmp(mice xx,mice yy){ if(xx.w!=yy.w)return xx.w>yy.w; if(xx.v!=yy.v)return xx.v<yy.w; return xx.index<yy.index;}void print_ans(int i){ printf("%d\n",a[i].index); if(!out[i])return ; print_ans(out[i]);}int main(){ int l=1; int i,j; int Max=-INF,pos; while(~scanf("%d %d",&a[l].w,&a[l].v)) { a[l].index=l; l++; } memset(d,0,sizeof(d)); memset(out,0,sizeof(out)); sort(a+1,a+l+1,cmp); for(i=1; i<=l; i++)d[i]=1; for(i=1; i<=l; i++) { for(j=1; j<i; j++) { if(a[i].v>a[j].v&&a[i].w<a[j].w) { if(d[i]<d[j]+1) { d[i]=d[j]+1; out[i]=j; } } } if(Max<d[i]){Max=d[i],pos=i;} }printf("%d\n",Max); print_ans(pos); return 0;}
阅读全文
0 0
- HDU1160(LIS)
- hdu1160 LIS
- HDU1160-LIS&路径记录-J
- HDU1160 FatMouse's Speed LIS变种+路径
- hdu1160 FatMouse's Speed(LIS普通法)
- hdu1160(dp的lis模型)
- hdu1160
- hdu1160
- hdu1160 FatMouse's Speed 最长上升子序列 LIS
- hdu1160&&1087
- HDU1160 Cantor
- LIS
- LIS
- LIS
- LIS
- LIS
- LIS
- LIS
- MFC实现Spin控件和Edit控件合用
- Python 网络爬虫-正则表达式、BeautifulSoup、lxml三种提取方法
- nodejs 环境搭建
- 两个经纬度之间的距离计算
- yum搭建lnmp环境(CentOS6.4)
- hdu1160 LIS
- Oracle 11.2.0.4.0 RAC下DRM导致单节点宕机
- 数论
- Android下的配置管理之道之gerrit代码服务器搭建
- Longest Ordered Subsequence(dp)
- 微信公众号扫码支付 spring mvc
- P1119 灾后重建
- opencv 学习笔记(一)
- 17、图的应用