
动态规划-背包问题
___Evan
这个作者很懒,什么都没留下…
展开
-
HDU-2159 fate 二维背包
#include#includeint dp[101][101];int main(){ int n,m,k,s; int a,b; while(scanf("%d %d %d %d",&n,&m,&k,&s)!=EOF) //还需的经验值,保留的忍耐度,怪的种数和最多的杀怪数 { memset(dp,0,sizeof(dp)); for(int i=1;原创 2013-10-17 18:11:15 · 545 阅读 · 0 评论 -
HDU-3339 In Action 最短路+01背包
题目链接题目大意:要破坏掉一个电网, 有n个电站编号为1~n,每个电站有它自己的能量值。有一个军事基地编号为0,里面有无限个坦克,可以开到某个电站轰炸破坏掉电站,并且一个坦克只能破坏一个。现在要破坏掉其中一些电站,要让电网的总能量值损失一半以上, 并且要让所有执行任务的坦克去目的地路费最少。解题思路:先求最短路 每个点都有摧毁与不摧毁2个选择 于是联想到原创 2014-03-09 14:02:53 · 526 阅读 · 0 评论 -
POJ-3260 Coins 多重背包
#include "stdio.h"#include "string.h"int p[105],num[105];int dp[100005];int v;void CompletePacc(int cost,int weight) { int i; for(i=cost;i<=v;i++) if(dp[i]<dp[i-cost]+weight)原创 2013-10-17 18:09:03 · 516 阅读 · 0 评论 -
基础01背包
#include "stdio.h"#include "string.h"double dp[10005];int main(){ int m,n; while( scanf("%d%d",&m,&n)==2 && ( m||n ) ) { int v,i; double q; for( i=0;i<=m+1;i++原创 2013-11-02 22:29:50 · 524 阅读 · 0 评论 -
hud-2191多重背包问题
#include "stdio.h"#include "string.h"int p[105],h[105],c[105]; //价钱 重量 袋数int dp[105];int n;void CompletePacc(int p,int h) //第i种大米价格 第i种大米重量{ int i; for(i=p;i<=n;i++) if(dp[i]<dp[i-原创 2013-11-02 22:28:51 · 540 阅读 · 0 评论 -
hdu-2151 二维背包
#include "stdio.h"#include "string.h"int dp[1050][1050];int jy[1005],rn[1005];int n,m,k,s;int main(){ while( scanf("%d%d%d%d",&n,&m,&k,&s)==4 ) { memset(dp,0,sizeof(dp)); int i,j,q,flag=m+原创 2013-11-02 22:33:28 · 652 阅读 · 0 评论 -
hdu-1712 分组背包问题
#include "stdio.h"#include "string.h"int A[105][105];int dp[105];int main(){ int n,m,i,j,k; while( scanf("%d%d",&n,&m)==2 && ( n || m )) { for( i=1;i<=n;i++ ) { for( j=1;j<=m;j++ )原创 2013-11-02 22:34:31 · 591 阅读 · 0 评论 -
hdu-2639 01背包 第K优决策
/*比喻吧:如果想知道学年最高分,那么,只要知道每个班级的最高分,然后统计一遍就可以了。如果想知道学年前十呢?必须要知道每个班的前十名。心里模拟一下,这就是本题核心的算法。两种决策,就可以看作这个学年只有两个班。*/#include "stdio.h"#include "string.h"int n,V,kth;int v[105],p[105],dp[1005][35]; /原创 2013-11-02 22:31:38 · 599 阅读 · 0 评论 -
POJ 2533 最长递增子序列
//POJ 2533 n^2 版#include "stdio.h"#include "queue"#include "math.h"using namespace std;const int maxn = 1005;int n;int num[maxn],d[maxn];int main(){ //freopen("data.in","r",stdin); scanf("原创 2013-11-02 22:37:48 · 586 阅读 · 0 评论 -
Uva-10130 SuperSale 01背包
#include #include #include#include #include using namespace std;const int maxn = 1005;const int inf = 1<<30;int n,m;int val[maxn],w[maxn];int dp[maxn];int ZeroOnePacc( int v ){ memset( dp原创 2014-04-21 18:49:58 · 421 阅读 · 0 评论