Ural 1114 Boxes

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

 

转载于:https://www.cnblogs.com/crackpotisback/p/4847334.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值