Ural 1114. Boxes (DP)

Source: Internet
Author: User

Http://acm.timus.ru/problem.aspx? Space = 1 & num = 1114


There are n boxes and balls of two colors. The red balls and the basketball balls are A and B respectively. Now, you can freely put the ball into the box. Each box can be in one color, two colors. How many methods are available.


Set DP [I] [J] [k] to indicate that J red balls and K basketball balls are left in the I-th box. The state transition equation can be listed: DP [I] [J] [k] = Σ (DP [I-1] [JJ] [Kk]) (j <= JJ <= A and K <= KK <= B ).


#include <stdio.h>#include <iostream>#include <map>#include <set>#include <bitset>#include <list>#include <stack>#include <vector>#include <math.h>#include <string.h>#include <queue>#include <string>#include <stdlib.h>#include <algorithm>#define LL __int64//#define LL long long#define ULL unsigned long long#define eps 1e-9#define PI acos(-1.0)using namespace std;ULL dp[25][20][20];int main(){    int n,A,B;    while(~scanf("%d %d %d",&n,&A,&B))    {        memset(dp,0,sizeof(dp));        dp[0][A][B] = 1;        ULL ans = 0;        for(int i = 1; i <= n; i++)        {            for(int j = 0; j <= A; j++)            {                for(int k = 0; k <= B; k++)                {                   for(int jj = j; jj <= A; jj++)                   {                       for(int kk = k; kk <= B; kk++)                            dp[i][j][k] += dp[i-1][jj][kk];                   }                   if(i == n )                        ans += dp[i][j][k];                }            }        }        printf("%I64u\n",ans);    }    return 0;}


Ural 1114. Boxes (DP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.