Boxes
Time Limit: 600ms
Memory Limit: 16384KB
This problem will be judged on Ural. Original ID: 111464-bit integer IO format: %lld Java class name: (Any)
N boxes are lined up in a sequence (1 ≤ N ≤ 20). You have A red balls and B blue balls (0 ≤ A ≤ 15, 0 ≤ B ≤ 15). The red balls (and the blue ones) are exactly the same. You can place the balls in the boxes. It is allowed to put in a box, balls of the two kinds, or only from one kind. You can also leave some of the boxes empty. It's not necessary to place all the balls in the boxes. Write a program, which finds the number of different ways to place the balls in the boxes in the described way.
Input
Input contains one line with three integers N, A and B separated by space.
Output
The result of your program must be an integer written on the only line of output.
Sample Input
2 1 1
Sample Output
9
Source
解题:强行dp
$dp[i][j][k]表示前i个盒子放了j个红球k个蓝球的方案数$
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 21; 4 unsigned long long dp[maxn][maxn][maxn]; 5 int main() { 6 int N,A,B; 7 while(~scanf("%d%d%d",&N,&A,&B)) { 8 memset(dp,0,sizeof dp); 9 dp[0][0][0] = 1; 10 for(int i = 1; i <= N; ++i) 11 for(int j = 0; j <= A; ++j) 12 for(int k = 0; k <= B; ++k) 13 for(int a = 0; a <= j; ++a) 14 for(int b = 0; b <= k; ++b) 15 dp[i][j][k] += dp[i-1][a][b]; 16 unsigned long long ret = 0; 17 for(int i = 0; i <= A; ++i) 18 for(int j = 0; j <= B; ++j) 19 ret += dp[N][i][j]; 20 printf("%I64u ",ret); 21 } 22 return 0; 23 }