标签:
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1257
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 28771 Accepted Submission(s): 11328
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> using namespace std; const int oo = 1e9; int dp[100005]; int a[100005]; int main() { int n; while(~scanf("%d",&n)) { for(int i=1; i<=n; i++) { scanf("%d", &a[i]); } int x = a[1]; int ans = 1; dp[1] = a[1]; for(int i=1; i<=n; i++) { int flag = 0; int Min = oo; int t; for(int j=1;j<=ans;j++) { if(dp[j]>=a[i] && Min>dp[j]-a[i]) { Min = dp[j]-a[i]; t = j; flag = 1; } } if(flag) { dp[t] = a[i]; } else { dp[++ans] = a[i]; } } printf("%d\n",ans); } return 0; }
标签:
原文地址:http://www.cnblogs.com/mengzhong/p/5041634.html