82pts,求调
查看原帖
82pts,求调
1491104
Jimmy_gongtengxin2楼主2025/6/18 13:58

01背包但是WA两个点

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=10000;
int n,m;
pair<int,int> a[maxn];
int dp[maxn];
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i].first>>a[i].second;
	}
	for(int i=1;i<=n;i++){
		for(int j=m;j>=a[i].first;j--){
			dp[j]=max(dp[j],dp[j-a[i].first]+a[i].second);
		}
	}
	cout<<dp[m];
	return 0;
}
2025/6/18 13:58
加载中...