URAL1036. Lucky Tickets

链接

dp[i][j] += dp[i-1][j-g];背包吧

数据太大了 还是JAVA好用

 1 import java.io.*;

 2 import java.math.*;

 3 import java.text.*;

 4 import java.util.*;

 5 public class Big {

 6     public static void main(String[] args)

 7     {

 8         Scanner cin = new Scanner (System.in);

 9         BigInteger[][] dp;

10         dp  = new BigInteger[55][1010];

11         int i,j,g,s,n;

12         n = cin.nextInt();

13         s = cin.nextInt();

14         for(i = 0;  i <= n ; i++)

15             for(j = 0 ;j <= s ; j++)

16                 dp[i][j] = BigInteger.valueOf(0);

17         if(s%2!=0||s/n/2>9)

18         {

19             System.out.println(0);

20         }

21         else

22         {

23             s/=2;

24             for(i = 0 ; i <= 9 ; i++)

25                 dp[1][i] = BigInteger.valueOf(1);

26             for(i = 2; i <= n ; i++)

27             {

28                 for(j = 0 ; j <= s ; j++)

29                 {

30                     for(g = 0 ; g <= 9 ; g++)

31                     {

32                         if(g>j) break;

33                         dp[i][j]  = dp[i][j].add(dp[i-1][j-g]);

34                     }

35                 }

36             }

37             BigInteger ans;

38             ans = dp[n][s].multiply(dp[n][s]);

39             System.out.println(ans);

40         }

41     }

42 

43 }
View Code

 

你可能感兴趣的:(c)