hdu 1160
2016-05-28 20:30
232 查看
这个题目简单 但是wa了很久 一直找不到自己错在哪里 最后对比了一下别人代码 终于发现原来dp要初始化为1 以后要细心!
这个题目数据好水的说 看了网上很多没有进行二级排序的都过了 其实这个地方应该对相同的weight进行二级排序
#include <iostream> #include <algorithm> #include <stdlib.h> #include <string> #include <string.h> #include <stdio.h> #include <ctype.h> #include <sstream> #include <ostream> #include <cmath> #include <stack> #include <queue> #include <list> #define pi acos(-1) #define e exp(1) #define inf 0x3f3f3f3f using namespace std; struct node{ int weight;int speed;int num; }; int cmp(node s1,node s2) {if(s1.weight!=s2.weight) return s1.weight<s2.weight;return s1.speed>s2.speed;} node arr[1005]; int dp[1005]; int save[1005]; int main() { int a,b; int i=0; while(scanf("%d %d",&a,&b)!=EOF) { arr[i].weight=a;arr[i].speed=b;arr[i].num=i+1; ++i; } sort(arr,arr+i,cmp); memset(save,-1,sizeof(save)); dp[1]=1;int num=0; for(int j=1;j<i;j++) { dp[j]=1; for(int k=0;k<j;k++) if(arr[k].weight!=arr[j].weight&&arr[k].speed>arr[j].speed&&dp[k]+1>dp[j]) {dp[j]=dp[k]+1;save[j]=k;} } int big=0; for(int j=1;j<i;j++) if(dp[j]>big) {big=dp[j];num=j;} cout<<big<<endl; stack<int >s; while(num!=-1) {s.push(num);num=save[num];} while(!s.empty()) {cout<<arr[s.top()].num<<endl;s.pop();} return 0; }
相关文章推荐
- 和为S的两个数字
- 第15课:spark streaming源码解读之No Receives彻底思考
- Weka 3.8 无法打开package manager解决方法
- 第二阶段团队项目冲刺站立会议(五)
- 半监督学习
- C Tricks(八)—— 硬币和骰子的模拟
- ubuntu下安装mysql及卸载mysql方法
- spring error at ::0 can't find referenced pointcut解决办法
- 自动化测试万能论
- html练习Flex布局
- Not-null property references a transient value - transient instance must be saved before current ope
- Java 之 线程的创建和启动(二)
- java 进程 线程 线程状态转换
- ZBUS = MQ + RPC
- Java调用某一js文件中的方法,执行并返回结果
- KNN分类算法实现By Java
- tomcat启动过程中报libXrender.so.1: cannot open shared object file: No such file or directory
- 对学习java的心得体会1
- 关于Android Studio设置全屏主题时,app闪退的解决方案!
- Machine learning-------------SVM(support vector machines)