- 这题的dp怎么分析
- 学习dp的刷表法(这题的正推怎么做)
#include<iostream>
using namespace std;
const int N = 10010;
struct Node{
int a, b;
}works[N];
int f[N];
int cnt[N];
int n, k;
int main(){
cin >> n >> k;
for(int i = 1; i <= k; i ++){
int a, b;
cin >> a >> b;
works[i] = {a, b};
cnt[a] ++;
}
int j = k;
for(int i = n; i >= 1; i --)
if(cnt[i] == 0) f[i] = f[i + 1] + 1;
else
while(works[j].a == i)
f[i] = max(f[i], f[i + works[j --].b]);
cout << f[1] << endl;
return 0;
}