序列变换

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1449    Accepted Submission(s): 538

Problem Description

Input

Output

Case #i:

Sample Input
2 2 1 10 3 2 5 4

Sample Output
Case #1: 0 Case #2: 1

a[i] - a[j] >= i - j也就是a[i] - i >= a[j] - j，又因为i > j，所以a[j] < a[i]，所以构造a[i] - i的序列即可满足题意（数学是硬伤啊）

#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn 100010
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
int dp[maxn], dis[maxn];
int num, ans, m, n;
void lis(){
int test;
dp[1] = dis[1];
ans = 1;
for(int i = 2; i <= n; i++){
if(dis[i] >= dp[ans]){
test = ++ans;
}
else{
test = upper_bound(dp+1, dp+ans+1, dis[i])-dp;
}
dp[test] = dis[i];
}
}
int main(){
int t, kcase = 1;
scanf("%d", &t);
while(t--){
scanf("%d", &n);
memset(dis, 0, sizeof(dis));
memset(dp, 0, sizeof(dp));
num = 0;
for(int i = 1; i <= n; i++){
scanf("%d", &dis[i]);
dis[i] -= i;
}
lis();
printf("Case #%d:\n%d\n", kcase++, n-ans);
}
return 0;
}

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客