Clark and Harry are siblings. As they had been rivals since their early childhood, their father decided that both should concentrate on a different sport when they were thirteen. That way, they would not have to compete for success. Now both are twenty years old and excel in different fields: Clark plays chess while Harry participates in dart-tournaments.
Having won a series of three tournaments in a row, Harry started teasing Clark about not having as much success. Clark retorted that chess was less luck-based and thus more difficult. That offended Harry and led him to the reply that in order to play darts optimally, a lot of combinatorics are necessary. Clark returned an icy smile and the comment that memorizing all different late-games could hardly be called “combinatorics”.
This is how it came to the wager. Harry bets that he can find all possible late-games for generalized dart-boards where memorized late-games do not help him. When Clark showed him a list of possible dartboards, Harry had to admit that he probably bit off more than he can chew. As his friend, you have to help him!
A dart-board consists of different areas. Each area has an assigned score for hitting it. Each area also has a double- and a triple-field that are worth twice and three times the score of the area. The only exception is the area for the highest score: It has only a double- and no triple-field! Given the values of the different areas you have to find the number of possible scores that can be obtained with a given number of darts.
InputThe inputs start with a line containing a single integer n. Each of the n following lines contains one test case. Each test case starts with two integers 1 <= a <= 100; 1 <= k <= 50, the number of different areas on the
Having won a series of three tournaments in a row, Harry started teasing Clark about not having as much success. Clark retorted that chess was less luck-based and thus more difficult. That offended Harry and led him to the reply that in order to play darts optimally, a lot of combinatorics are necessary. Clark returned an icy smile and the comment that memorizing all different late-games could hardly be called “combinatorics”.
This is how it came to the wager. Harry bets that he can find all possible late-games for generalized dart-boards where memorized late-games do not help him. When Clark showed him a list of possible dartboards, Harry had to admit that he probably bit off more than he can chew. As his friend, you have to help him!
A dart-board consists of different areas. Each area has an assigned score for hitting it. Each area also has a double- and a triple-field that are worth twice and three times the score of the area. The only exception is the area for the highest score: It has only a double- and no triple-field! Given the values of the different areas you have to find the number of possible scores that can be obtained with a given number of darts.
dart-board and the number of darts. a integers 1 <= s i <= 100 follow. si is the score for hitting area i. All scores are distinct. Remember that each area has a double- and, with exception of the area with the highest score, a triple-field. It is always possible to score 0 with any given dart by not hitting the board.
OutputThe output for every test case begins with a line containing “Scenario #i:”, where i is the number of the scenario counting from 1. After that, output a single line containing the number of different scores that can be obtained with k darts on the given board. Terminate each test case with an empty line.
Sample Input
3 21 3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 25 2 2 20 10 1 50 1Sample Output
Scenario #1: 172 Scenario #2: 9 Scenario #3:
101
思路:通过01背包来实现数值最大化,从最小的数值找到最大的数值,判断每个数值是否可能存在;存在后进行数据统计,统计出可能的得分次数;
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int d[105][20005];
int main()
{
int t,c=1;
scanf("%d",&t);
while(t--)
{
memset(d,0,sizeof(d));
int n,sum=0,m,i,j,k,p=0,x=0,a[105];
scanf("%d%d",&n,&m);//飞镖板上不同区域的数量和飞镖数量;
//录入击中区域的得分;
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]>a[p])//找出最大数的数标
p=i;
}
x=3*a[p]*m;
d[0][0]=1; //边界;
for(i=0;i<n;i++) //板子
for(j=1;j<=m;j++) //取东西的方法数
for(k=0;k<=x;k++) //可能的价值
if(d[j-1][k]) //是否达到k价值
{
//策略
d[j][k]=1; // 在扔第j个飞镖时,获得K的分数是可能的;
d[j][k+a[i]]=1; //在 扔第J个飞镖时,获得2倍得分是可能的;
d[j][k+2*a[i]]=1; //在扔第j个飞镖时,获得3倍得分是可能的;
if(p!=i)
d[j][k+3*a[i]]=1; // 获得3倍得分的时候;
}
for(i=0;i<=x;i++)
if(d[m][i]) //在扔M个飞镖时能够得到i分数;
sum++; //统计可能得分的情况;
printf("Scenario #%d:",c++);
printf("%d\n\n",sum);
}
}