【dp 背包变形】 poj 1837
#include <cstdio>
#include <memory.h>
#include<iostream>
using namespace std;
int dp[][]; //状态数组dp[i][j]
int main(int i,int j,int k)
{
int n; //挂钩数
int g; //钩码数
int c[]; //挂钩位置
int w[]; //钩码重量
cin>>n>>g;
for(i=;i<=n;i++)
cin>>c[i];
for(i=;i<=g;i++)
cin>>w[i];
memset(dp,,sizeof(dp)); //达到每个状态的方法数初始化为0
dp[][]=; //7500为天枰达到平衡状态时的平衡度
for(i=;i<=g;i++)
for(j=;j<=;j++)
if(dp[i-][j]) //优化
for(k=;k<=n;k++)
if(j+w[i]*c[k]<)
dp[i][ j+w[i]*c[k] ] += dp[i-][j]; //状态方程
cout<<dp[g][]<<endl;
return ;
}
【dp 背包变形】 poj 1837的更多相关文章
- POJ 1337 A Lazy Worker(区间DP, 背包变形)
Description There is a worker who may lack the motivation to perform at his peak level of efficiency ...
- POJ 1837 -- Balance(DP)
POJ 1837 -- Balance 转载:優YoU http://user.qzone.qq.com/289065406/blog/1299341345 提示:动态规划,01背包 初看此题第 ...
- FZU 2214 Knapsack problem 01背包变形
题目链接:Knapsack problem 大意:给出T组测试数据,每组给出n个物品和最大容量w.然后依次给出n个物品的价值和体积. 问,最多能盛的物品价值和是多少? 思路:01背包变形,因为w太大, ...
- Codeforces Round #214 (Div. 2) C. Dima and Salad (背包变形)
C. Dima and Salad time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- codeforce Gym 101102A Coins (01背包变形)
01背包变形,注意dp过程的时候就需要取膜,否则会出错. 代码如下: #include<iostream> #include<cstdio> #include<cstri ...
- HDU 2639 Bone Collector II(01背包变形【第K大最优解】)
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- P1282 多米诺骨牌 (背包变形问题)
题目描述 多米诺骨牌有上下2个方块组成,每个方块中有1~6个点.现有排成行的 上方块中点数之和记为S1,下方块中点数之和记为S2,它们的差为|S1-S2|.例如在图8-1中,S1=6+1+1+1=9, ...
- Balance POJ - 1837
Description Gigel has a strange "balance" and he wants to poise it. Actually, the device i ...
- 【01背包变形】Robberies HDU 2955
http://acm.hdu.edu.cn/showproblem.php?pid=2955 [题意] 有一个强盗要去几个银行偷盗,他既想多抢点钱,又想尽量不被抓到.已知各个银行 的金钱数和被抓的概率 ...
随机推荐
- POJ 1704 Georgia and Bob(阶梯博弈+证明)
POJ 1704 题目链接 关于阶梯博弈有如下定理: 将所有奇数阶梯看作n堆石头,做Nim,将石头从奇数堆移动到偶数堆看作取走石头,同样地,异或值不为0(利己态)时,先手必胜. 定理证明看此博:htt ...
- wamp配置sendmail发送邮件
下载 sendmail ( 地址: http://www.glob.com.au/sendmail/sendmail.zip ) [PHP.ini 配置] [mail function]; For W ...
- 8.Hibernate的多对多关联映射
1.创建如下数据库脚本 --1.1 项目表 create table PROJECT ( proid ) not null, proname ) ) ; --1.2 项目表主键 alter table ...
- 【转】动态字节码技术跟踪Java程序
Whats is Java Agent? .. java.lang.instrument.Instrumentation 之前有写 基于AOP的日志调试 讨论一种跟踪Java程序的方法, 但不是很 ...
- HDU 1240 Asteroids!(BFS)
题目链接 Problem Description You're in space.You want to get home.There are asteroids.You don't want to ...
- Python & virtualenv使用说明
virtualenv是virtual environment的缩写,可以创建独立的Python环境,用起来比较干净: 安装(已安装pip 或者 easy_install): 如果使用pip: pi ...
- qsort函数辅助函数compare函数的编写
qsort的第四个参数,辅助函数compare的关于不同排序对象的不同写法: 一.对int类型数组排序 ]; int compare(const void *a, const void *b) { r ...
- yii2 windows 安装
Yii是一个高性能的,适用于开发WEB2.0应用的PHP框架. Yii自带了丰富的功能 ,包括MVC,DAO/ActiveRecord,I18N/L10N,缓存,身份验证和基于角色的访问控制,脚手架, ...
- ios NSComparator 三种枚举类型
NSComparator有3种枚举类型 NSOrderedDescending 降序,但是用他可以实现升序或者降序都没问题. NSOrderedAscending 升序,但是目前没有使用出任何效果.. ...
- shape的使用
android在布局边缘位置处理圆角的两个办法: 1),一个是直接让美工切一张带有圆角的图片. 2),使用shape来解决. 第一种不在赘述,主要讲一下第二中方法来实现. 上边缘出现圆角,下边缘正常的 ...