标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1200 Accepted Submission(s): 448
题解:
改变系列使成为单调递增子序列;那么只需要dp[i]-dp[j]>=i-j就好了;再加上单调递增子序列的求法;
dp[i]-dp[j]>=i-j即为dp[i]-i>=dp[j]-j;
代码:
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<vector> using namespace std; const int MAXN = 1e5 + 100; int num[MAXN]; int dp[MAXN]; vector<int>vec; /* int main(){ int T, N, kase = 0; scanf("%d", &T); while(T--){ vec.clear(); scanf("%d", &N); for(int i = 0; i < N; i++){ scanf("%d", num + i); num[i] -= i; if(upper_bound(vec.begin(), vec.end(), num[i]) == vec.end()){ vec.push_back(num[i]); } else{ int p = upper_bound(vec.begin(), vec.end(), num[i]) - vec.begin(); vec[p] = num[i]; } } printf("Case #%d:\n%d\n", ++kase, N - vec.size()); } return 0; } */ int main(){ int T, N, kase = 0; scanf("%d", &T); while(T--){ scanf("%d", &N); memset(dp, 0, sizeof(dp)); int ans = 0; for(int i = 0; i < N; i++){ scanf("%d", num + i); for(int j = 0; j < i; j++){ if(num[i] - num[j] >= i - j){ dp[i] = dp[j] + 1; ans = max(ans, dp[i]); } } } printf("Case #%d:\n%d\n", ++kase, N - ans - 1); } return 0; }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/5373794.html