#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的更多相关文章

  1. POJ 1337 A Lazy Worker(区间DP, 背包变形)

    Description There is a worker who may lack the motivation to perform at his peak level of efficiency ...

  2. POJ 1837 -- Balance(DP)

     POJ 1837 -- Balance 转载:優YoU   http://user.qzone.qq.com/289065406/blog/1299341345 提示:动态规划,01背包 初看此题第 ...

  3. FZU 2214 Knapsack problem 01背包变形

    题目链接:Knapsack problem 大意:给出T组测试数据,每组给出n个物品和最大容量w.然后依次给出n个物品的价值和体积. 问,最多能盛的物品价值和是多少? 思路:01背包变形,因为w太大, ...

  4. 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 ...

  5. codeforce Gym 101102A Coins (01背包变形)

    01背包变形,注意dp过程的时候就需要取膜,否则会出错. 代码如下: #include<iostream> #include<cstdio> #include<cstri ...

  6. HDU 2639 Bone Collector II(01背包变形【第K大最优解】)

    Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  7. P1282 多米诺骨牌 (背包变形问题)

    题目描述 多米诺骨牌有上下2个方块组成,每个方块中有1~6个点.现有排成行的 上方块中点数之和记为S1,下方块中点数之和记为S2,它们的差为|S1-S2|.例如在图8-1中,S1=6+1+1+1=9, ...

  8. Balance POJ - 1837

    Description Gigel has a strange "balance" and he wants to poise it. Actually, the device i ...

  9. 【01背包变形】Robberies HDU 2955

    http://acm.hdu.edu.cn/showproblem.php?pid=2955 [题意] 有一个强盗要去几个银行偷盗,他既想多抢点钱,又想尽量不被抓到.已知各个银行 的金钱数和被抓的概率 ...

随机推荐

  1. Java中SJBArrayList自己简单实现ArrayList

    /** * 自己实现ArrayList * @author zyyt * */ public class SJBArrayList { //存放SJBArrayList中的元素 transient O ...

  2. iOS开发下架在AppStore中销售的app

    1.登陆开发者账号 2.选择itunes connect 选择我的app 3.选择要下架的app 4.价格与销售范围 5.销售范围 6.点击存储 //如果想要重新在AppStore中进行销售只需要选择 ...

  3. 编写高质量iOS代码的52个有效方法2-1

    一.变量的定义位置(用{}声明示例变量或者用@property属性声明实例变量) 1.用{}声明示例变量: 此方法生命的实例变量,编译器在编译时,会自动计算其偏移量(表示该变量距离存放对象的内存区域的 ...

  4. F#中的自定义隐式转换

    我们知道隐式变换在可控情况下会使代码变得简洁.熟悉C#的都知道C#中可以自定义隐式变换,例如 public class A { private int data; public static impl ...

  5. SSH 两个表全套增删改(运动员住宿管理)

    0.创建如下oracle的命令 create table HOTALINFO ( HOTALID ) not null, HOTALNAME ) not null, HOTALADDRESS ) no ...

  6. OpenCV2.x自学笔记——最大类间方差法OTSU

    推荐用法:(参数勿动) threshold(gray,binary,0,255,CV_THRESH_OTSU+CV_THRESH_BINARY);

  7. use include to read a file

    #include<iostream> #include<fstream> using namespace std; void process(string filename) ...

  8. Django中的Form表单

    Django中已经定义好了form类,可以很容易的使用Django生成一个表单. 一.利用Django生成一个表单: 1.在应用下创建一个forms文件,用于存放form表单.然后在forms中实例华 ...

  9. Bootstrap介绍

    Bootstrap是基于HTML.CSS和JavaScript开源的前端开发工具包. 1.响应式布局: 效果:根据浏览器的宽度来调整页面布局. 例如: <html lang="en&q ...

  10. OpenGL4.x不支持gluPerspective函数。故备份之

    template <typename type> inline mat4<type> mat4<type>::perspectiveProjection(type ...