这题感觉可以贪心,但 WA 了,只有10分,应该很好举出反例,但我没想出来。
算出每个数要在它前面删多少个数才能使它在正确的位置上(就是a[i]-i),然后取最大值。
可以看一下代码:
#include <cstdio>
#include <algorithm>
using namespace std;
int n, a[1010], t[10010], ans=-1;
int main()
{
scanf("%d", &n);
for(int i=1; i<=n; i++)
scanf("%d", &a[i]);
for(int i=1; i<=n; i++)
if(i-a[i]>=0) t[i-a[i]]++;
for(int i=0; i<=10000; i++)
ans=max(ans, t[i]);
printf("%d", ans);
return 0;
}
求大佬解答,谢谢orz