zoukankan      html  css  js  c++  java
  • dp hdu 5464 Clarke and problem

    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(1T10) - the number of test cases. 
    T test cases follow. 
    The first line contains two positive integers n,p(1n,p1000) 
    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.

    ~开心,自己根据写出来的,还特别简洁。

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <cmath>
     6 #include <algorithm>
     7 #include <vector>
     8 #define ll __int64
     9 #define mod 1000000007
    10 using namespace std;
    11 int dp[1005][1005],nums[1005];
    12 int main(void)
    13 {
    14     int t;
    15     cin>>t;
    16     while(t--)
    17     {
    18         int n,p;
    19         scanf("%d %d",&n,&p);
    20         for(int i = 1; i <= n; i++)
    21         {
    22             scanf("%d",&nums[i]);
    23             nums[i] %= p;
    24             if(nums[i] < 0)
    25                 nums[i] += p;
    26         }
    27 
    28         memset(dp,0,sizeof(dp));
    29         dp[0][0] = 1;
    30         for(int i = 1; i <= n; i++)
    31         {
    32             for(int j = 0; j <= p; j++)
    33             {
    34                 dp[i][j] = dp[i-1][j] + dp[i-1][(j-nums[i]+p)%p];
    35                 dp[i][j] %= mod;
    36             }
    37         }
    38         printf("%d
    ",dp[n][0]);
    39     }
    40     return 0;
    41 }
  • 相关阅读:
    NET5 ORM 六大新功能
    牛逼程序员必须要掌握金字塔思维
    实体类转Json的2种方法
    怎么使用jquery阻止页面的离开或卸载
    GitHub的用法:到GitHub上部署项目
    搭建个人服务器
    远程服务器上部署本地项目
    java.nio.ByteBuffer中flip,rewind,clear方法的区别
    eclipse Run On Server 异常:could not load the Tomcat Server configuration at Servers omcat V5.0 Sertomcat
    throw与throws的区别
  • 原文地址:https://www.cnblogs.com/henserlinda/p/4827335.html
Copyright © 2011-2022 走看看