背包问题
,
infinity°º
stay hungry stay foolish
展开
-
hdu2159二维背包
#include<bits/stdc++.h>using namespace std;#define LOCAL //输入输出这个提交时要删了const int maxn=105;int n,m,k,s,v[maxn],c[maxn],dp[maxn][maxn];int main(){ #ifdef LOCAL freopen(".\\in.txt","r",stdin); freopen(".\\out.txt","w",stdout); #endif while(ci.原创 2021-05-25 19:54:26 · 69 阅读 · 0 评论 -
hdu4508同1248
#include<bits/stdc++.h>using namespace std;int n,m;int val[105];int cost[105];int dp[100005];int main(){ while(cin>>n) { for(int i=1;i<=n;i++) { cin>>val[i]>>cost[i]; } cin>>m; for(int i=0;i<=m;i++).原创 2021-05-24 20:59:45 · 80 阅读 · 0 评论 -
hdu3496二维费用背包(的01背包)
#include<bits/stdc++.h>using namespace std;const int maxn=105;int T,n,m,l,v[maxn],t[maxn],dp[maxn*10][maxn];int main(){ cin>>T; while(T--){ cin>>n>>m>>l; memset(dp,-1,sizeof(dp)); for(int j=l;j>=0;j--) dp[j].原创 2021-05-24 20:41:15 · 99 阅读 · 0 评论 -
hdu1248可重复取(从前往后)要遍历求max
#include <bits/stdc++.h> //从前往后 恰满 using namespace std;const int maxn=1e4+5;int T,n,V,v[maxn],w[maxn],dp[maxn];int main(){ int i,j; cin>>T; n=3; v[1]=w[1]=150;v[2]=w[2]=200;v[3]=w[3]=350; while(T--){ scanf("%d",&V); memset(.原创 2021-05-12 20:17:48 · 70 阅读 · 0 评论 -
hdu2191 同种类型可重复取 但有限制,最多取ni件(1或2或..ni。 不能累加1,2..ni)
#include <bits/stdc++.h>using namespace std;const int maxn=105;int T,n,V,v[maxn],w[maxn],dp[maxn],m[maxn];int main(){ int i,j,k; cin>>T; while(T--){ //int ans=0; cin>>V>>n; for(i=1;i<=n;i++){ scanf("%d%d%d",&.原创 2021-05-12 19:51:43 · 61 阅读 · 0 评论 -
hdu1114完全背包恰好装满(dp[v]即所求)无数次使用(前往后)
#include <bits/stdc++.h> //恰满足的 最小 using namespace std;const int maxn=1e4+5;const int inf=0x3f3f3f3f;int T,n,V,v[maxn],w[maxn],dp[maxn];int main(){ int e,f,i,j; cin>>T; while(T--){ scanf("%d%d",&e,&f); V=f-e; scanf("%d",&.原创 2021-05-12 16:48:34 · 80 阅读 · 0 评论 -
hdu2062 01
#include <bits/stdc++.h>const int maxn=1e3+5; using namespace std;int T,n,V,v[maxn],w[maxn],dp[maxn];int main(){ cin>>T; int i,j; while(T--){ memset(dp,0,sizeof(dp)); cin>>n>>V; for(i=1;i<.原创 2021-05-12 16:14:18 · 49 阅读 · 0 评论