(1160)HDU-类LIS
来源:互联网 发布:淘宝采集软件是干嘛的 编辑:程序博客网 时间:2024/06/04 17:56
这道题有点最长上升子序列的意思·····,只不过限制条件多了一个必须保证w[i]<w[i+1]&&s[i]>s[i+1],存路径的时候保存前驱节点就可以了。
#include<iostream>
#include<cstdio>#include<string.h>
#include<string>
#include<set>
#include<algorithm>
#include<cmath>
#include<stack>
#define ll __int64
#define MAX 1000009
using namespace std;
int dp[MAX];
int pre[MAX];
struct node
{
int w;
int s;
int num;
} op[MAX];
bool cmp(node A,node B)
{
if(A.w!=B.w)
return A.w<B.w;
else
return A.s>A.s;
}
int main()
{
int n,m;
int i,j;
int k = 0;
while(scanf("%d%d",&n,&m)!=EOF)
{
op[k].w = n;
op[k].s = m;
op[k].num = k + 1;
k++;
}
//cout<<k<<endl;
sort(op,op+k,cmp);
// for(i = 0; i<k; i++)
// {
// cout<<op[i].w<<" "<<op[i].s<<" "<<op[i].num<<endl;
// }
memset(dp,0,sizeof(dp));
dp[0] = 1;
for(i = 1; i<k; i++)
{
dp[i] = 1;
for(j = 0; j<i; j++)
{
if(op[i].w>op[j].w&&op[i].s<op[j].s&&dp[j]+1>dp[i])
{
dp[i] = dp[j] + 1;
pre[i] = j;
}
}
}
int _max = 0;
int flag = 0;
for(i = 0; i<k; i++)
{
if(_max<dp[i])
{
flag = i;
_max = dp[i];
}
}
cout<<_max<<endl;
stack<int>S;
while(flag)//这里不断找前驱节点然后存进stack里
{
S.push(flag);
flag = pre[flag];
}
while(!S.empty())
{
cout<<op[S.top()].num<<endl;
S.pop();
}
return 0;
}
0 0
- (1160)HDU-类LIS
- hdu 1160 LIS
- [DP-LIS] HDU 1160
- hdu 1160 FatMouse's Speed (LIS)
- DP LIS 记录路径 hdu 1160
- HDU 1160 FatMouse's Speed[LIS]
- HDU-1160 FatMouse's Speed(LIS)
- HDU 1160 FatMouse's Speed(LIS)
- hdu 1160 FatMouse's Speed(LIS)
- HDU 1160 FatMouse's Speed(LIS)
- HDU 1160 FatMouse's Speed(LIS)
- hdu 1160 FatMouse's Speed ( LIS )
- HDU 1160 FatMouse's Speed(LIS)
- HDU 4001 DP LIS
- hdu 1677 (LIS+贪心)
- hdu 3564 Another Lis
- HDU 4604 lower_bound,LIS
- HDU 1677 LIS
- 对梯度下降法的简单理解
- 动态规划-村子募捐问题
- 【hibernate框架】一对多(多对一)双向关联(XML实现)
- java封装JDBC通用类
- Mongodb的读书笔记(02)
- (1160)HDU-类LIS
- Linux下的命令总结笔记(一)
- 【hibernate框架】一对多(多对一)双向关联(Annotation实现)
- 加载动态链接库时提示Can't load IA 32-bit .dll on a AMD 64...
- 人人网2015研发笔试卷E
- leetcode 日经贴,python code -Find Peak Element
- 【hibernate框架】多对多单向关联(XML实现)
- Versions 上传问题
- Bitmap Byte 和Drawable 的相互转换