C - Zero Escape
Time Limit:1000MS Memory Limit:131072KB 64bit IO Format:%I64d & %I64u
Appoint description:
Description
Zero Escape, is a visual novel adventure video game directed by Kotaro Uchikoshi (you may hear about ever17?) and developed by Chunsoft.
Stilwell is enjoying the first chapter of this series, and in this chapter digital root is an important factor.
This is the definition of digital root on Wikipedia:
The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.
For example, the digital root of is , because and .
In the game, every player has a special identifier. Maybe two players have the same identifier, but they are different players. If a group of players want to get into a door numbered , the digital root of their identifier sum must be .
For example, players can get into the door , but players can't.
There is two doors, numbered and . Maybe , but they are two different door.
And there is players, everyone must get into one of these two doors. Some players will get into the door , and others will get into the door .
For example:
players are , ,
There is only one way to distribute the players: all players get into the door . Because there is no player to get into the door , the digital root limit of this door will be ignored.
Given the identifier of every player, please calculate how many kinds of methods are there, .
Stilwell is enjoying the first chapter of this series, and in this chapter digital root is an important factor.
This is the definition of digital root on Wikipedia:
The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.
For example, the digital root of is , because and .
In the game, every player has a special identifier. Maybe two players have the same identifier, but they are different players. If a group of players want to get into a door numbered , the digital root of their identifier sum must be .
For example, players can get into the door , but players can't.
There is two doors, numbered and . Maybe , but they are two different door.
And there is players, everyone must get into one of these two doors. Some players will get into the door , and others will get into the door .
For example:
players are , ,
There is only one way to distribute the players: all players get into the door . Because there is no player to get into the door , the digital root limit of this door will be ignored.
Given the identifier of every player, please calculate how many kinds of methods are there, .
Input
The first line of the input contains a single number
, the number of test cases.
For each test case, the first line contains three integers , and .
Next line contains integers , describing the identifier of every player.
, , ,
For each test case, the first line contains three integers , and .
Next line contains integers , describing the identifier of every player.
, , ,
Output
For each test case, output a single integer in a single line, the number of ways that these
players can get into these two doors.
Sample Input
4 3 9 1 1 2 6 3 9 1 2 3 3 5 2 3 1 1 1 1 1 9 9 9 1 2 3 4 5 6 7 8 9
Sample Output
1 0 10 60
题意:有n个球员,每个人有一个数字,有两球门,每个门有一个数字,要把n个球员放到全部放到两个球门里,允许只使用
一个球门,但是必须将所有球员放入球门里,放入规则是 :放入球门人的数字相加得到的和sum,再将sum每一位相交得到sum2,这样一直加,直到sum i 为个位数,并且sum i = 该球门的数字;
dp[i][j]表示前i个数中“和”为j的个数,那么 dp[i][j] = dp[ i-1 ][ j ] + dp[i-1][ j - num[ i ] ];num[i]即为第i个球员的编号
具体看代码吧:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
using namespace std;
const int maxn=1e5+10,mod=258280327;
typedef long long LL;
int dp[maxn][10];
int num[maxn];
int SUM(int a,int b)
{
int ans=a+b;
ans%=9;
if(ans==0)
return 9;
return ans;
}
int main()
{
int t;
int n,a,b;
scanf("%d",&t);
while(t--)
{
scanf("%d%d%d",&n,&a,&b);
int sum=0;
for(int i=1; i<=n; i++)
{
scanf("%d",&num[i]);
sum+=num[i];
}
sum%=9;
int ans=0;
memset(dp,0,sizeof(dp));
dp[0][0]=1;
if(sum==b%9)
{
ans++;
}
if(sum==((a+b)%9))
{
for(int i=1; i<=n; i++)
{
for(int j=0; j<=9; j++)
{
if(j>=num[i])
dp[i][j]=dp[i-1][j]+dp[i-1][j-num[i]];
else
dp[i][j]=dp[i-1][j]+dp[i-1][-num[i]+j+9];
dp[i][j]=dp[i][j]%mod;
}
}
printf("%d\n",dp[n][a]+ans);
}
else
{
if(sum==a%9)
ans++;
printf("%d\n",ans);
}
}
//cout << "Hello world!" << endl;
return 0;
}