黄 dp 求调
查看原帖
黄 dp 求调
781159
Lovely_Elaina楼主2024/11/28 09:43

1

WA on #6

思路看了一下,和几篇题解差不多但是实现有点不同(?

#include <bits/stdc++.h>
// #define int long long
#define endl '\n'
using namespace std;
const int N = 1e5+5;
const int M = 1e6+5;

struct node{
    int v,b;
}f[M];

int n,m;

// inline bool cmp(node x,node y){
//     return x.a < y.a;
// }

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> n;
    
    int p;
    for(int i = 1; i <= n; i++){
        // cin >> a[i].a >> a[i].b;
        cin >> p >> f[p].b;
        m = max(m,p);
        f[i].v = 1;
    }
    
    // sort(a+1,a+1+n,cmp);
    
    for(int i = 1; i <= m; i++){
        if(f[i].b == 0){
            f[i].v = f[i-1].v;
        // cout << f[i].v << " ";
            continue;
        }
        
        if(i-f[i].b-1 > 0){
            f[i].v = max(f[i].v,f[i-f[i].b-1].v+1);
        }
        // cout << f[i].v << " ";
    }
    // cout << endl;
    
    int ans = 1;
    for(int i = 1; i <= m; i++)
        ans = max(ans,f[i].v);
    cout << n-ans << endl;
    return 0;
}

2

为什么答案 ans 初始化必须为 1 不能为 0 否则会 WA on #3

理论上一定存在至少一个塔价值为 11 啊喵喵 /jy

2024/11/28 09:43
加载中...