poj 1837 Balance (0 1 背包)
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 10326 | Accepted: 6393 |
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
int dp[25][15005];
int n,g,c[25],w[25],i,j;
while(cin>>n>>g)
{
for(i=1;i<=n;i++)
cin>>c[i];
for(i=1;i<=g;i++)
cin>>w[i];
memset(dp,0,sizeof(dp));
dp[0][7500]=1;
for(i=1;i<=g;i++)
for(j=0;j<=15000;j++) if(dp[i-1][j])
{
for(int k=1;k<=n;k++)
dp[i][j+c[k]*w[i]]+=dp[i-1][j];
}
cout<<dp[g][7500]<<endl;
}
return 0;
}
poj 1837 Balance (0 1 背包)的更多相关文章
- POJ 1837 -- Balance(DP)
POJ 1837 -- Balance 转载:優YoU http://user.qzone.qq.com/289065406/blog/1299341345 提示:动态规划,01背包 初看此题第 ...
- POJ 1745 【0/1 背包】
题目链接:http://poj.org/problem?id=1745 Divisibility Time Limit: 1000MS Memory Limit: 10000K Total Sub ...
- poj 1837 Balance(背包)
题目链接:http://poj.org/problem?id=1837 Balance Time Limit: 1000MS Memory Limit: 30000K Total Submissi ...
- POJ 1837 Balance 01背包
题目: http://poj.org/problem?id=1837 感觉dp的题目都很难做,这道题如果不看题解不知道憋到毕业能不能做出来,转化成了01背包问题,很神奇.. #include < ...
- POJ 1837 Balance 水题, DP 难度:0
题目 http://poj.org/problem?id=1837 题意 单组数据,有一根杠杆,有R个钩子,其位置hi为整数且属于[-15,15],有C个重物,其质量wi为整数且属于[1,25],重物 ...
- POJ 1837 Balance(01背包变形, 枚举DP)
Q: dp 数组应该怎么设置? A: dp[i][j] 表示前 i 件物品放入天平后形成平衡度为 j 的方案数 题意: 有一个天平, 天平的两侧可以挂上重物, 给定 C 个钩子和G个秤砣. 2 4 - ...
- POJ 1837 Balance
Balance Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 9240 Accepted: 5670 Description G ...
- [poj 1837] Balance dp
Description Gigel has a strange "balance" and he wants to poise it. Actually, the device i ...
- poj 1837 Balance 动态规划 (经典好题,很锻炼思维)
题目大意:给你一个天平,并给出m个刻度,n个砝码,刻度的绝对值代表距离平衡点的位置,并给出每个砝码的重量.达到平衡状态的方法有几种. 题目思路:首先我们先要明确dp数组的作用,dp[i][j]中,i为 ...
随机推荐
- 345 Reverse Vowels of a String 反转字符串中的元音字母
编写一个函数,以字符串作为输入,反转该字符串中的元音字母.示例 1:给定 s = "hello", 返回 "holle".示例 2:给定 s = "l ...
- Leetcode03---Longest Substring Without Repeating Characters
Description: Given a string, find the length of the longest substring without repeating characters. ...
- fieldset ----- 不常用的HTML标签
fieldset 元素可将表单内的相关元素分组. <fieldset> 标签将表单内容的一部分打包,生成一组相关表单的字段. 当一组表单元素放到 <fieldset> 标签内时 ...
- Android基础TOP3_1:纵横屏切换
在Res下建立layout-port文件夹 为竖屏时加载的界面: 建立layout-land 文件夹 为横屏加载的界面
- 汇总——WEB前端资源网
前端攻城师 爱思资源网 HTML5吧 0101后花园 前端网 编程教程和源代码示例 Javascript中文网 Web前端资源网 移动端HTML5资源整理 Web开发者 SegmentFault 前端 ...
- 05--QT常用的类
http://blog.csdn.net/HMSIWTV/article/category/1128561/2 Qt常用类(1)—— 开端 使用Qt进行编程必须对 Qt 中常用的类有一定的 ...
- cesium的学习
一.学习资料:http://cesiumjs.org/tutorials.html,看完6个教程后对图层加载.控件控制开关.地形数据叠加.模型添加.相机控制.图形绘制有一点了解.这也是cesium的主 ...
- CAD通过扩展记录实体向数据库读写用户自定义的全局数据(com接口VB语言)
VB代码实现如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ...
- Unity的分辨率
问题: 强制设置程序运行的分辨率 解决办法: 在程序开始运行时就对分辨率进行设定 设定方法如下: void GetResolution() { int width = Screen.currentRe ...
- uva 1586 Molar mass(Uva-1586)
这题做的相当的复杂...之前做的现在应该能简单一点了写的. 我的代码: #include <bits/stdc++.h> using namespace std; main() { int ...