码迷,mamicode.com
首页 > 其他好文 > 详细

hdu 5464 Clarke and problem(dp)

时间:2015-09-22 20:23:57      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

Problem Description
 
 
Clarke is a patient with multiple personality disorder. One day, Clarke turned into a student and read a book.
Suddenly, a difficult problem appears: 
You are given a sequence of number a1,a2,...,an and a number p. Count the number of the way to choose some of number(choose none of them is also a solution) from the sequence that sum of the numbers is a multiple of p(0 is also count as a multiple of p). Since the answer is very large, you only need to output the answer modulo 109+7

 

 

Input
The first line contains one integer T(1≤T≤10) - the number of test cases. 
T test cases follow. 
The first line contains two positive integers n,p(1≤n,p≤1000) 
The second line contains n integers a1,a2,...an(|ai|≤109).

 

 

 

Output
For each testcase print a integer, the answer.

 

 

 

Sample Input
1 
2 3 
1 2

 

 

 

Sample Output
2

 

 
 Hint: 2 choice: choose none and choose all.
 

 

Source
 

 附上中文题目:

克拉克是一名人格分裂患者。某一天,有两个克拉克(aaa和bbb)在玩一个方格游戏。  
这个方格是一个n∗mn*mn∗m的矩阵,每个格子里有一个数ci,jc_{i, j}c?i,j??。  
aaa想开挂,想知道如何打败bbb。  
他们要玩qqq次游戏,每一次做一次操作:  
1. 取出当中的一个子矩阵(x1,y1)−(x2,y2)(x_1, y_1)-(x_2, y_2)(x?1??,y?1??)−(x?2??,y?2??)玩游戏。两个人轮流行动,每一次只能从这个子矩阵中的一个方格ci,jc_{i, j}c?i,j??中减掉一个的数d(1≤d≤ci,j)d(1 \le d \le c_{i, j})d(1≤d≤c?i,j??),当一个格子的数为000时则不能减。如果操作完后另一者无法操作,那么胜利。否则失败。现在aaa作为先手,想知道是否存在一种方案使得自己胜利。  
2. 将ci,jc_{i, j}c?i,j??的数改成bbb  

 

d(i,j)表示前i个数,模pj的方案数,则容易得到  d(0,0)=1;

状态转移:dp[i][j]+=dp[i-1][j];   dp[i][(j+a[i])%p]+=(dp[i-1][j]);

最后的答案为 dp[n][0]

技术分享
 1 #pragma comment(linker, "/STACK:1024000000,1024000000")
 2 #include<iostream>
 3 #include<cstdio>
 4 #include<cstring>
 5 #include<cmath>
 6 #include<math.h>
 7 #include<algorithm>
 8 #include<queue>
 9 #include<set>
10 #include<bitset>
11 #include<map>
12 #include<vector>
13 #include<stdlib.h>
14 #include <stack>
15 using namespace std;
16 int dirx[]={0,0,-1,1};
17 int diry[]={-1,1,0,0};
18 #define PI acos(-1.0)
19 #define max(a,b) (a) > (b) ? (a) : (b)  
20 #define min(a,b) (a) < (b) ? (a) : (b)
21 #define ll long long
22 #define eps 1e-10
23 #define MOD 1000000007
24 #define N 1006
25 #define inf 1e12
26 int n,p;
27 int a[N];
28 int dp[N][N];
29 int main()
30 {
31     int t;
32     scanf("%d",&t);
33     while(t--){
34         scanf("%d%d",&n,&p);
35         for(int i=1;i<=n;i++){
36             scanf("%d",&a[i]);
37             a[i]=(a[i]%p+p)%p;
38         }
39         
40         memset(dp,0,sizeof(dp));
41         dp[0][0]=1;
42         for(int i=1;i<=n;i++){
43             for(int j=0;j<p;j++){
44                 dp[i][j]+=dp[i-1][j];
45                 dp[i][j]%=MOD;
46 
47                 dp[i][(j+a[i])%p]+=(dp[i-1][j]);
48                 dp[i][(j+a[i])%p]%=MOD;
49             }
50         }
51         
52         printf("%d\n",dp[n][0]);
53         
54     }
55     return 0;
56 }
View Code

 

hdu 5464 Clarke and problem(dp)

标签:

原文地址:http://www.cnblogs.com/UniqueColor/p/4830174.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!