标签:style blog http io ar os sp for on
#include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include <string> #include <cctype> #include <vector> #include <cstdio> #include <cmath> #include <queue> #include <stack> #include <map> #include <set> #define maxn 1010 #define _ll __int64 #define ll long long #define INF 0x3f3f3f3f #define Mod 1000000007 #define pp pair<int,int> #define ull unsigned long long using namespace std; int p,w[maxn],s[maxn],dp[maxn]; bool ma[maxn][maxn]; void build() { memset(ma,0,sizeof(ma)); for(int i=1;i<p;i++) { for(int j=i+1;j<p;j++) { if(w[i]<w[j]&&s[i]>s[j]) ma[i][j]=1; else if(w[j]<w[i]&&s[j]>s[i]) ma[j][i]=1; } } } int dfs(int x) { int& ans=dp[x]; if(ans>0) return ans; ans=1; for(int i=1;i<p;i++) if(ma[x][i])ans=max(ans,dfs(i)+1); return ans; } void output(int x) { printf("%d\n",x); for(int i=1;i<p;i++) if(ma[x][i]&&dp[x]==dp[i]+1) { output(i); break; } } int main() { p=1; while(scanf("%d %d",w+p,s+p)!=EOF)++p; build(); memset(dp,-1,sizeof(dp)); int ans=-INF,indx; for(int i=1;i<p;i++) if(ans<dfs(i)) { ans=dp[i]; indx=i; } printf("%d\n",ans); output(indx); return 0; }
Uva 10131-Is Bigger Smarter?(DP)
标签:style blog http io ar os sp for on
原文地址:http://blog.csdn.net/qq_16255321/article/details/41827489