完全背包
来源:互联网 发布:python进入命令行模式 编辑:程序博客网 时间:2024/06/05 07:27
完全背包是指 物品无限使用的,所以在枚举的时候要将for循环用++的方式来枚举。#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<algorithm>using namespace std;const int maxn=10010;int s[maxn],t[maxn],dp[maxn];int main(){memset(s,0,sizeof(s));memset(t,0,sizeof(t));memset(dp,0,sizeof(dp));int m,n,i,j,k;scanf("%d%d",&n,&m);for(i=1;i<=m;i++)scanf("%d%d",&s[i],&t[i]);for(i=1;i<=m;i++)for(int j=t[i];j<=n;j++)//与01背包的差别就在这里 dp[j]=max(dp[j],dp[j-t[i]]+s[i]);printf("%d",dp[n]);return 0;}
1 0
- 完全背包
- 完全背包
- 完全背包
- 完全背包
- 完全背包
- 完全背包!!
- 完全背包
- 完全背包
- 完全背包
- 完全背包
- 完全背包
- 完全背包
- 完全背包
- 完全背包
- 完全背包
- 完全背包
- 完全背包
- 完全背包
- 用__attribute__((deprecated))管理过时的代码
- 20160830MYSQL的密码更改基本操作
- post和get传值
- 手机充电器原理
- linux的cpu资源调优方法
- 完全背包
- 【Codeforces Round #369 (Div. 2)】Codeforces 711B Chris and Magic Square
- java中File类的使用方法
- libxml2库 读取xml文件,写xml文件
- Matlab2015编译生成Dll并在VS2010环境下应用的具体操作步骤(64位系统)
- LeetCode: Reverse Linked List
- retrofit2 post url拼接设置问题
- Ultra-QuickSort
- 基于zookeeper简单实现分布式锁