这是背包问题啊!!!
by Lijunzhuo @ 2024-01-21 15:48:29
当我没说话
by Lijunzhuo @ 2024-01-21 15:49:32
@[Lijunzhuo](/user/734720) 只有50分,有一个非常刁钻的测试点,T=1000,M=100,我开10000都没用,我2556,输出2558(就问你√8不√8)
by hiYE_ame @ 2024-01-21 15:53:26
我给你调调
by Lijunzhuo @ 2024-01-21 15:54:46
人家的跟我一模一样,怎么就对了呢
```cpp
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 1010;
int n, m;
int f[N];
int main(){
cin >> m >> n;
for (int i = 1; i <= n; i ++ ){
int v, w;
cin >> v >> w;
for (int j = m; j >= v; j -- )
f[j] = max(f[j], f[j - v] + w);
}
cout << f[m] << endl;
return 0;
}
```
by hiYE_ame @ 2024-01-21 15:55:37
h,你猜哪错了
by Lijunzhuo @ 2024-01-21 15:56:43
@[hiYE_ame](/user/766454)
@[hiYE_ame](/user/766454)
@[hiYE_ame](/user/766454)
by Lijunzhuo @ 2024-01-21 15:57:13
@[hiYE_ame](/user/766454)
```cpp
for(int j=t-1;j>a;j--){
```
```cpp
cout<<f[t-1]<<endl;
```
这还叫一模一样?
by xiaoshumiao @ 2024-01-21 15:57:42
我给你找到了
by Lijunzhuo @ 2024-01-21 15:57:44
```cpp
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int t,m,a,b,f[10100];
int main(){
cin>>t>>m;
for(int i=0;i<m;i++){
cin>>a>>b;
for(int j=t-1;j>=a;j--){ //是>=不是>
f[j]=max(f[j],f[j-a]+b);
}
}
cout<<f[t-1]<<endl;
return 0;
}
```
by Lijunzhuo @ 2024-01-21 15:58:31