码迷,mamicode.com
首页 > 其他好文 > 详细

uva 10131

时间:2017-09-07 13:30:14      阅读:115      评论:0      收藏:0      [点我收藏+]

标签:eof   col   nod   .net   algorithm   inf   cst   int   for   

https://vjudge.net/problem/UVA-10131

   直接暴力N^2dp就好了,最后找一下路径输出,很经典的DAG题目。

  

 1 #include<iostream>
 2 #include<cstring>
 3 #include<cstdio>
 4 #include<algorithm>
 5 #include<vector>
 6 #include<stack>
 7 using namespace std;
 8 #define inf 0x3f3f3f3f
 9 struct node{int w,s,u;}P[1005];
10 bool cmp(node A,node B){return A.w<B.w;}
11 int f[1005];
12 int main()
13 {
14     int N=1,M,i,j,k;
15     while(cin>>P[N].w){cin>>P[N].s;P[N].u=N;N++;}N--;
16     sort(P+1,P+1+N,cmp);
17     memset(f,0,sizeof(f));
18     int ans=0;
19     for(i=1;i<=N;++i)
20     {
21         int maxn=0;
22         for(j=1;j<i;++j)
23         {
24             if(P[j].w<P[i].w&&P[j].s>P[i].s&&f[j]>maxn){
25                 maxn=f[j];
26             }
27         }
28         f[i]=maxn+1;
29         if(f[i]>ans) ans=f[i];
30     }
31     printf("%d\n",ans);
32     stack<int>s;
33     for(i=N;i&&ans;--i)
34     {
35         if(f[i]==ans){ans--;s.push(i);}
36     }
37     while(!s.empty()) {printf("%d\n",P[s.top()].u);s.pop();}
38     return 0;
39 }

 

uva 10131

标签:eof   col   nod   .net   algorithm   inf   cst   int   for   

原文地址:http://www.cnblogs.com/zzqc/p/7488931.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!