AcWing 1023 买书 题解 (动态规划—DP—背包问题)

AcWing 1023 买书 题解 (动态规划—DP—背包问题),第1张

AcWing 1023 买书 题解 (动态规划—DP—背包问题)

原题传送门

#include

using namespace std;

const int N = 1100;

int n;
int f[N];
int v[4] = {10, 20, 50, 100};

int main()
{
	
	cin>>n;
	f[0] = 1;//初始化,因为总体积为0(空集)也是一种方案 
	for(int i = 0; i < 4; i ++ ){
		for(int j = 0; j <= n; j ++ ){//遍历体积
		 
			if(j >= v[i]) f[j] += f[j - v[i]];
		}
	}
	
	cout<					
										


					

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5703391.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-18
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存