Balance

Description

Gigel has a strange "balance" and he wants to poise it. Actually, the device is different from any other ordinary balance. 
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 input has the following structure: 
• 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

The output contains the number M representing the number of possibilities to poise the balance.

Sample Input

2 4
-2 3
3 4 5 8

Sample Output

2大意:天枰问题,把背包变成零,因为下标不会出现负数,所以重新选择一个平衡点15*25*20=7500递归方程 : dp[i][k+w[j]*v[i]]+=dp[i-1][j], 输出dp[m][7500],dp[i][j]表示经过加东西之后肯能到达平衡的点。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
int dp[30][30000];
using namespace std;
int main(){
int w[25],v[25];
int n,m;
while(~scanf("%d%d", &n,&m)){
    for(int i = 1; i <= n; i++)
    scanf("%d",&w[i]);
    for(int i = 1; i <= m; i++)
    scanf("%d",&v[i]);

    memset(dp, 0, sizeof(dp));

    dp[0][7500] = 1;
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= n; j++){
           for(int k = 0; k <= 15000; k ++){
                dp[i][k+w[j]*v[i]]+=dp[i-1][k];
             }
          }
      }
      printf("%d\n", dp[m][7500]);
    }
    return 0;
}

 
时间: 2024-11-10 13:13:52

Balance的相关文章

LB(Load balance)负载均衡集群--{LVS-[NAT+DR]单实例实验+LVS+keeplived实验} 菜鸟入门级

LB(Load balance)负载均衡集群 LVS-[NAT+DR]单实例实验 LVS+keeplived实验 LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统. 逻辑可分为: 1调度层 (Director):它是整个集群对外面的前端机,负责将客户的请求发送到一组服务器上执行,而客户认为服务是来自一个IP地址(我们可称之为虚拟IP地址)上的. 2[服务器池(server pool)/集群层(Real server)]:是一组真正执行客

轻量级网络流量转发工具 - Balance

Balance是一款具有负载均衡和故障转移功能的TCP代理软件.支持IPV6地址的监听和转发,支持rr轮询和ip hash. 某些功能可以替代iptables,比如讲来自本地的80端口转发到8080上: iptables是这样写的: iptables -t nat -A PREROUTING -d 192.168.1.1 -p tcp --dport 80 -j DNAT --to 192.168.1.1:8080 balance只需要这样: balance 80 localhost:8080

益计算Shprotification.v6.8.15.22+Heat.Balance.v6.12.27.36+Cold.Balance.v2.6.14.18

热增益计算Shprotification.v6.8.15.22+Heat.Balance.v6.12.27.36+Cold.Balance.v2.6.14.18 Andrey.Shirshov.Shprotification.v6.8.15.22 Andrey.Shirshov.Heat.Balance.v6.12.27.36 Andrey.Shirshov.Cold.Balance.v2.6.14.18   "现代ASHRAE标准参考数据用于从人.设备.确定热输入的人工照明,半透明的击剑系数(

POJ2142 The Balance (扩展欧几里德)

本文为博主原创文章,欢迎转载,请注明出处 www.cnblogs.com/yangyaojia The Balance 题目大意  你有一个天平(天平左右两边都可以放砝码)与重量为a,b(1<=a,b<=10000)的两种砝码.让你求出一种方案称出重为c(1<=c<=50000)的物品,如有多种方案,请输出两种砝码需要数量的总和最小的方案. 输入 有若干行,每行三个数,a,b,c. 结束时用0 0 0表示. 输出 若干行,每行两个数,表示每个询问中a的数量与b的数量 如果无解输出 

POJ 2142 The Balance

The Balance Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 6325   Accepted: 2787 Description Ms. Iyo Kiffa-Australis has a balance and only two kinds of weights to measure a dose of medicine. For example, to measure 200mg of aspirin usi

Oracle RAC 服务器端连接负载均衡(Load Balance)

Oracle RAC服务器端的负载均衡是根据RAC中各节点的连接负荷数情况,将新的连接请求分配到负荷最小的节点上去.当数据库处于运行时,RAC中各节点的PMON进程每3秒会将各自节点的连接负荷数更新到service_register.而对于节点中任意监听器故障或监听器意外失败时,PMON进程会每1秒钟检查当前节点上的监听是否重启,以获得最新的负载信息来及时调整负载均衡.本文主要演示suse 10 + oracle 10g rac下的服务器端的负载均衡. 有关客户端的负载均衡可参考      Or

uva 673 Parentheses Balance

Parentheses Balance You are given a string consisting of parentheses () and []. A string of this type is said to be correct: (a)if it is the empty string (b)if A and B are correct, AB is correct, (c)if A is correct, (A) and [A] is correct. Write a pr

How to manage and balance “Huge Data Load” for Big Kafka Clusters---reference

1. Add Partition Tool Partitions act as unit of parallelism. Messages of a single topic are distributed to multiple partitions that can be stored and served on different servers. Upon creation of a topic, the number of partitions for this topic has t

Hdu 1709 The Balance

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1709 题意: 给N个整数,每个数只能使用一次.将他们组合起来,最后看在1~sum(a[1]..a[N])这些数里有多少数是这N个数组合不出来的. 先输出这些数的个数,再将这些数输出来.如果个数是0,那么不需要输出数. 案例分析: input: 3 1 2 4 output: 0 -->1(||4-1-2) , 2(||4-2) , 1+2(||4-1) , 4  , 1+4 , 2+4 , 1+2+

HDU1709 The Balance 【母函数】

The Balance Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 5463    Accepted Submission(s): 2214 Problem Description Now you are asked to measure a dose of medicine with a balance and a number