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

Ural 1114 Boxes

时间:2015-09-29 22:03:57      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:

Boxes

Time Limit: 600ms
Memory Limit: 16384KB
This problem will be judged on Ural. Original ID: 1114
64-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 NA 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\n",ret);
21     }
22     return 0;
23 }
View Code

 

Ural 1114 Boxes

标签:

原文地址:http://www.cnblogs.com/crackpotisback/p/4847334.html

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