#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. ggplot2 scale相关设置2—时间设置

    在scale设置中,常用的日期方面的设置函数包括: scale_x_date(),scale_y_date(),scale_x_datetime(),scale_y_datetime()   接下来, ...

  2. linux命令 time

    功能:用于计算命令执行的世界 语法:  time command 例如: hbg@root:~/dl$ time ls111     apple.sh  b.txt            duplic ...

  3. agentX各个角色功能

    AgentX Roles  1.master An entity acting in a master agent role performs the following  functions: -  ...

  4. Chapter 14_5 _ENV和load

    load在加载代码块时,通常使用全局环境去初始化代码块的_ENV上值. 然而,load选项的第四个参数给出的值就是供_ENV用的.(loadfile函数参数也是一样) 举一个有关初始化的例子,假如我们 ...

  5. redis数据类型:lists

    redis的list类型其实就是一个每个子元素都是string类型的双向链表. 我们可以通过push,pop操作从链表的头部或者尾部添加删除元素,这样list即可以作为 栈,又可以作为队列. lpus ...

  6. windows服务-log4net的使用

    本文转自http://www.cnblogs.com/puzi0315/archive/2012/08/08/2628966.html Log4net监控服务状态 对于比较复杂的逻辑,可以使用log4 ...

  7. 常用的meta标签

    <!-- 关键字,搜所引擎 SEO --> <meta http-equiv="keywords" content="关键字1,关键字2,...&quo ...

  8. 关于 HIVE Beeline 问题

    1  启动 hiveserver2 服务,启动 beeline -u jdbc:hive2:// 正常 ,启动 beeline -u jdbc:hive2://127.0.0.1:10000 包如下错 ...

  9. 1-10w之间的整数中有几个完全平方数

    #include "stdio.h" #include<math.h> void main() { ,x,y; printf("1-10w之间的整数中有以下几 ...

  10. play框架概述

    今天是来百度实习的第四天,在项目过程中mentor说会用到play框架,当时就一个晕啊.Java还有一个叫play框架,作为一个从大三开始用java的重度javaer,居然不知道这个框架的存在,内心一 ...