POJ1837 Balance[分组背包]
| Time Limit: 1000MS | Memory Limit: 30000K | |
| Total Submissions: 13717 | Accepted: 8616 |
Description
It orders two arms of negligible weight and each arm's length is 15. Some hooks are attached to these arms and Gigel wants to hang up some weights from his collection of G weights (1 <= G <= 20) knowing that these weights have distinct values in the range 1..25. Gigel may droop any weight of any hook but he is forced to use all the weights.
Finally, Gigel managed to balance the device using the experience he gained at the National Olympiad in Informatics. Now he would like to know in how many ways the device can be balanced.
Knowing the repartition of the hooks and the set of the weights write a program that calculates the number of possibilities to balance the device.
It is guaranteed that will exist at least one solution for each test case at the evaluation.
Input
• the first line contains the number C (2 <= C <= 20) and the number G (2 <= G <= 20);
• the next line contains C integer numbers (these numbers are also distinct and sorted in ascending order) in the range -15..15 representing the repartition of the hooks; each number represents the position relative to the center of the balance on the X axis (when no weights are attached the device is balanced and lined up to the X axis; the absolute value of the distances represents the distance between the hook and the balance center and the sign of the numbers determines the arm of the balance to which the hook is attached: '-' for the left arm and '+' for the right arm);
• on the next line there are G natural, distinct and sorted in ascending order numbers in the range 1..25 representing the weights' values.
Output
Sample Input
2 4
-2 3
3 4 5 8
Sample Output
2
Source
题意:c个挂钩n个砝码,全用上,平衡多少种方案
//
// main.cpp
// poj1837
//
// Created by Candy on 9/22/16.
// Copyright © 2016 Candy. All rights reserved.
// #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=,sh=;
int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
int c,n;
int pos[N],w[N],f[N][(sh<<)+];
void dp(){
f[][sh]=;
for(int i=;i<=n;i++)
for(int j=sh<<;j>=;j--)
if(f[j]){
for(int k=;k<=c;k++) f[i][j+pos[k]*w[i]]+=f[i-][j];
} }
int main(int argc, const char * argv[]) {
c=read();n=read();
for(int i=;i<=c;i++) pos[i]=read();
for(int i=;i<=n;i++) w[i]=read();
dp();
printf("%d",f[n][sh]);
return ;
}
POJ1837 Balance[分组背包]的更多相关文章
- POJ1837 Balance 背包
题目大意: 有一个天平,天平左右两边各有若干个钩子,总共有C个钩子(每个钩子有相对于中心的距离,左负右正),有G个钩码,求将钩码全部挂到钩子上使天平平衡的方法的总数. 将每个砝码看作一组,组内各个物品 ...
- HDU 1712 ACboy needs your help(分组背包)
题意:给你n的课程组,每个课程组有m个课程,每个课程有一个完成时间与价值.问在m天内每组课程组最多选择一个,这样可以得到的最大价值是多少 题解:分组背包,其实就是每个课程组进行01背包,再在课程组内部 ...
- Codeforces Round #383 (Div. 2) D 分组背包
给出一群女孩的重量和颜值 和她们的朋友关系 现在有一个舞台 ab是朋友 bc是朋友 ac就是朋友 给出最大承重 可以邀请这些女孩来玩 对于每一个朋友团体 全邀请or邀请一个or不邀请 问能邀请的女孩的 ...
- HDU 3033 分组背包变形(每种至少一个)
I love sneakers! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 1712 分组背包
ACboy needs your help Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- Codeforces Round #383 (Div. 2) D. Arpa's weak amphitheater and Mehrdad's valuable Hoses(分组背包+dsu)
D. Arpa's weak amphitheater and Mehrdad's valuable Hoses Problem Description: Mehrdad wants to invit ...
- HDU3535AreYouBusy[混合背包 分组背包]
AreYouBusy Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- Codevs1378选课[树形DP|两种做法(多叉转二叉|树形DP+分组背包)---(▼皿▼#)----^___^]
题目描述 Description 学校实行学分制.每门的必修课都有固定的学分,同时还必须获得相应的选修课程学分.学校开设了N(N<300)门的选修课程,每个学生可选课程的数量M是给定的.学生选修 ...
- hdu1712 分组背包
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1712 题意:有n门课程,和m天时间,完成mp[i][j]得到的价值为第i行j列的数字,求最 ...
随机推荐
- 【JavaScript】内置对象Math
Math是具有用于数学常数和函数的属性和方法一内置对象.不是函数对象. 描述编辑 不像其他的全局对象,Math不是一个构造函数.所有属性和方法Math都是静态的.你指的是常数pi为Math.PI你调用 ...
- .net c# 视频剪切抓取缩略图
public string Cut(string ffmpegPath, string videoPath, string savePath, string imgSize, int sleepTim ...
- ABAP--在查询条件只包含部分索引字段时,如何使用索引
One of the most important considerations when writing a select statement against a large table is th ...
- 利用Ajax增删改Sharepoint List Item
在使用一个工具的是想要在本地的HTML文件或者JS,修改Sharepoint List中的数据. 如下是找到的方法.不知道还有其他方法没.IE中可以使用.记得加载Jquery. 如果是Chrome 浏 ...
- Understanding the Uncertain Geographic Context Problem
"The areal units (zonal objects) used in many geographical studies are arbitrary, modifiable, a ...
- Sharepoint学习笔记—习题系列--70-576习题解析 -(Q78-Q80)
Question 78 You are designing an application configuration approach for a custom SharePoint 2010 app ...
- 配置redis外网可访问,并只允许指定的ip可访问redis
开启redis 允许外网IP 访问 在 Linux 中安装了redis 服务,当在客户端通过远程连接的方式连接时,报could not connect错误. 错误的原因很简单,就是没有连接上redis ...
- webbench 压力测试
原文 webbench最多可以模拟3万个并发连接去测试网站的负载能力,个人感觉要比Apache自带的ab压力测试工具好用,安装使用也特别方便,并且非常小. 主要是 -t 参数用着比较爽,下面参考了张宴 ...
- Android studio git 本地仓库和远程仓库节点对比
1.初始状态 2.本地修改文件,然后commit 3.本地再次修改文件,然后commit 4.本地push 从上图可以看出,push完成后,本地仓库的节点和远程仓库的节点是一样的.
- xcode7无证书真机调试 Error: An App ID with identifier "*" is not avaliable. Please enter a different string.
1. Error: An App ID with identifier "*" is not avaliable. Please enter a different string. ...