(dp)acwing 423. 采药

423. 采药

题目链接
在这里插入图片描述

#include<iostream>

#include<algorithm>
using namespace std;
int main() {
    
    
	int t, m;
	cin >> t >> m;
	int a,b;
	int dp[1010] = {
    
     0 };
	for (int i = 1; i <= m; i++) {
    
    
		cin >> a>>b;
		for (int j = t; j >= a; j--) {
    
    
			dp[j] = max(dp[j], dp[j - a] + b);
		}
	}
	cout << dp[t];
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_46028214/article/details/115326519
今日推荐