UVA - 10131 Is Bigger Smarter?
2014-10-23 13:46
330 查看
dp,不多说。。。短板还是在于编程能力。。。
遇到一个目前还没搞清楚的问题,elephant里重载小于号存在问题,这里本地codeblocks必须加const,oj上却不用加。。。。重新回去学c++吧。。
遇到一个目前还没搞清楚的问题,elephant里重载小于号存在问题,这里本地codeblocks必须加const,oj上却不用加。。。。重新回去学c++吧。。
#include<cstdio> #include<algorithm> #include<cstring> #define MAX 1100 using namespace std; struct elephant { int w,i,index; bool operator < (elephant other)const { if(w<other.w) return true; else if(w==other.w&&i>=other.i) return true; return false; } }ele[MAX]; int dp[MAX],father[MAX]; void print(int index) { if(index<0) return ; print(father[index]); printf("%d\n",ele[index].index); } int main() { int a,b,i=0,j,t,maxx; while(scanf("%d %d",&a,&b)!=EOF) { ele[i].index=i+1,ele[i].w=a,ele[i].i=b; //printf("%d %d %d\n",ele[i].w,ele[i].i,ele[i].index); i++; } //printf("%da",i); sort(ele,ele+i); //for(j=0;j<i;j++) // printf("%d %d %d\n",ele[j].w,ele[j].i,ele[j].index); memset(dp,0,MAX*4); dp[0]=1,father[0]=-1; for(j=1;j<i;j++) { dp[j]=1,father[j]=-1; for(t=0;t<j;t++) { if(ele[t].w<ele[j].w&&ele[t].i>ele[j].i) { if(dp[t]+1>dp[j]) { dp[j]=dp[t]+1; father[j]=t; } } } } maxx=0; for(j=1;j<i;j++) if(dp[j]>dp[maxx]) maxx=j; printf("%d\n",dp[maxx]); print(maxx); return 0; }
相关文章推荐
- UVa 10131 Is Bigger Smarter?
- UVa 10131: Is Bigger Smarter?
- UVA 10131 Is Bigger Smarter?(DP)
- UVA 10131 Is Bigger Smarter ? DP ,Commencel
- UVA 10131 - Is Bigger Smarter? (动态规划)
- UVa 10131 Is Bigger Smarter? (DP&LIS)
- UVa 10131 Is Bigger Smarter? (LDS+数据结构排序)
- uva 10131 Is Bigger Smarter?(DAG最长路)
- UVA - 10131 Is Bigger Smarter?
- UVa Problem 10131 Is Bigger Smarter? (越大越聪明?)
- UVa 10131 - Is Bigger Smarter?
- UVa 10131 - Is Bigger Smarter?
- UVA 10131 Is Bigger Smarter?
- uva 10131 Is Bigger Smarter?
- UVA 10131 Is Bigger Smarter? (DP,最长条件子序列)
- UVa 10131 - Is Bigger Smarter?
- UVa 10131: Is Bigger Smarter?
- UVA 10131 - Is Bigger Smarter? (动态规划)
- UVA 10131-Is Bigger Smarter?
- UVA - 10131 - Is Bigger Smarter? (动态规划,LIS)