TC 609DIV2(950)

Problem Statement

     Vocaloids Gumi, Ia, and Mayu love singing. They decided to make an album composed of S songs. Each of the S songs must be sung by at least one of the three Vocaloids. It is allowed for some songs to be sung by any two, or even all three Vocaloids at the same time. The number of songs sang by Gumi, Ia, and Mayu must be gumi, ia, and mayu, respectively.
They soon realized that there are many ways of making the album. Two albums are considered different if there is a song that is sung by a different set of Vocaloids. Let X be the number of possible albums. Since the number X can be quite large, compute and return the number (X modulo 1,000,000,007).

Definition

    
Class: VocaloidsAndSongs
Method: count
Parameters: int, int, int, int
Returns: int
Method signature: int count(int S, int gumi, int ia, int mayu)
(be sure your method is public)

Limits

    
Time limit (s): 2.000
Memory limit (MB): 256

Constraints

- S will be between 1 and 50, inclusive.
- gumi, ia and mayu will be each between 1 and S, inclusive.

Examples

0)  
    
3
1
1
1
Returns: 6
In this case, there are 3 songs on the album. And Gumi, Ia, Mayu will each sing one song. There are 3*2*1 = 6 ways how to choose which Vocaloid sings which song.
1)  
    
3
3
1
1
Returns: 9
Gumi will sing all three songs. Ia and Mayu can each choose which one song they want to sing.
2)  
    
50
10
10
10
Returns: 0
It is not possible to record 50 songs if each Vocaloid can only sing 10 of them.
3)  
    
18
12
8
9
Returns: 81451692
 
4)  
    
50
25
25
25
Returns: 198591037

还有950的。。确实比以前的1000简单点 

数比较小了 开了四维的dp 

dp[i][j][k][g]表示第i首歌曲时 三人分别唱了j,k,g次。

 1 #include <iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<stdlib.h>
 6 #include<cmath>
 7 using namespace std;
 8 #define LL long long
 9 #define mod 1000000007
10 LL dp[52][52][52][52];
11 class VocaloidsAndSongs
12 {
13     public :
14     int count(int S, int gumi, int ia, int mayu)
15     {
16         LL ans=0;
17         int o[4];
18         o[1] = gumi;o[2] =ia;o[3] = mayu;
19         int i,j,k,g;
20         dp[1][2][1][1] = 1;
21         dp[1][1][2][1] = 1;
22         dp[1][1][1][2] = 1;
23         dp[1][2][2][1] = 1;
24         dp[1][2][1][2] = 1;
25         dp[1][1][2][2] = 1;
26         dp[1][2][2][2] = 1;
27         for(i = 2 ;i <= S ; i++)
28         for(j = 1; j <= o[1]+1 ; j++)
29         for(k = 1 ; k <= o[2]+1 ; k++)
30             for(g = 1 ; g <= o[3]+1 ; g++)
31             {
32                // if(j+k+g+3>=i)
33                // {
34                     dp[i][j][k][g] = (dp[i][j][k][g]+dp[i-1][j-1][k][g]+dp[i-1][j][k-1][g]+dp[i-1][j][k][g-1])%mod;
35                     dp[i][j][k][g] = (dp[i][j][k][g]+dp[i-1][j-1][k-1][g]+dp[i-1][j][k-1][g-1]+dp[i-1][j-1][k][g-1])%mod;
36                     dp[i][j][k][g] = (dp[i][j][k][g]+dp[i-1][j-1][k-1][g-1])%mod;
37                     //cout<<dp[i][j][k][g]<<" "<<i<<" "<<j<<" "<<k<<" "<<g<<endl;
38                // }
39             }
40         ans = dp[S][o[1]+1][o[2]+1][o[3]+1]%mod;
41         return ans;
42     }
43 };
View Code

 

 
posted @ 2014-02-16 20:29  _雨  阅读(330)  评论(0编辑  收藏  举报