hdu4906 Our happy ending 2014 Multi-University Training Contest 4
2014-08-03 14:44
489 查看
Our happy ending
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 703 Accepted Submission(s): 225
Problem Description
There is an old country and the king fell in love with a devil. The devil always asks the king to do some crazy things. Although the king used to be wise and beloved by his people. Now he is just like a boy in love and can’t refuse any request from the devil.
Also, this devil is looking like a very cute Loli.
Y*wan still remember the day he first meets the devil. Now everything is done and the devil is gone. Y*wan feel very sad and suicide.
You feel guilty after killing so many loli, so you suicide too.
Nobody survive in this silly story, but there is still some hope, because this is just a silly background story during one programming contest!
And the last problem is:
Given a sequence a_1,a_2,...,a_n, if we can take some of them(each a_i can only be used once), and they sum to k, then we say this sequence is a good sequence.
How many good sequence are there? Given that each a_i is an integer and 0<= a_i <= L.
You should output the result modulo 10^9+7.
Input
The first line contains an integer T, denoting the number of the test cases.
For each test case, the first line contains 3 integers n, k, L.
T<=20, n,k<=20 , 0<=L<=10^9.
Output
For each cases, output the answer in a single line.
Sample Input
1 2 2 2
Sample Output
6
Author
WJMZBMR
Source
2014 Multi-University Training Contest
4
Recommend
用到状态压缩,代码不长
比赛的时候看了一眼,不会做,赛后参考了神牛的思路/article/7154413.html
#include <iostream> #include <cstdio> #include <cstring> using namespace std; const int mod=1e9+7; int dp[(1<<20)+10]; int main(){ int T,N,K,L; scanf("%d",&T); while(T--){ scanf("%d%d%d",&N,&K,&L); memset(dp,0,sizeof(dp)); dp[0]=1; int t=max(L-K,0); if(t==L-K)L=K; for(int i=0;i<N;i++){ for(int j=(1<<K)-1;j>=0;j--){ if(dp[j]==0)continue; int temp=dp[j]; int p=t*1ll*dp[j]%mod;//这个地方不转换成ll会wa for(int l=L;l>=1;l--){ int s=j|(1<<(l-1))|((j<<l)&((1<<K)-1)); dp[s]=(dp[s]+temp)%mod; } dp[j]=(p+dp[j])%mod; } } int ans=0; for(int i=(1<<K-1);i<(1<<K);i++)ans=(ans+dp[i])%mod; printf("%d\n",ans); } return 0; }
相关文章推荐
- hdoj4906 Our happy ending(2014 Multi-University Training Contest 4)
- HDU 4906 Our happy ending(2014 Multi-University Training Contest 4)
- 【动态规划】【2014 Multi-University Training Contest 4】Our happy ending
- HDU 4893 Wow! Such Sequence!(2014 Multi-University Training Contest 3)
- HDU 4898 The Revenge of the Princess’ Knight ( 2014 Multi-University Training Contest 4 )
- 2014 Multi-University Training Contest 5 HDOJ 4911 Inversion
- 2014 Multi-University Training Contest 5 1010 Matrix multiplication 涨姿势系列
- 2014 Multi-University Training Contest 6 Fighting the Landlords
- HDU 4941 Magical Forest(2014 Multi-University Training Contest 7)
- HDU 4944 FSF’s game(2014 Multi-University Training Contest 7)
- hdu 4925 Apple Tree 2014 Multi-University Training Contest 6
- hdu 4864 Task---2014 Multi-University Training Contest 1
- 2014 Multi-University Training Contest 2 1011 ZCC Loves Codefires 解题报告
- HDU 4888 Redraw Beautiful Drawings(2014 Multi-University Training Contest 3)
- HDU 4900 NO ACM NO LIFE(概率+枚举+搜索)(2014 Multi-University Training Contest 4)
- HDU 4913 Least common multiple(2014 Multi-University Training Contest 5)
- 2014 Multi-University Training Contest 6小记
- HDU 4946 Area of Mushroom(2014 Multi-University Training Contest 8)
- 2014 Multi-University Training Contest 8 部分题目解题报告
- hdu 4941 Magical Forest 2014 Multi-University Training Contest 7