hdu 4906 Our happy ending 状压dp
来源:互联网 发布:创业软件股份ceo 编辑:程序博客网 时间:2024/06/06 03:25
http://acm.hdu.edu.cn/showproblem.php?pid=4906
Our happy ending
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1275 Accepted Submission(s): 447
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.
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.
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
12 2 2
Sample Output
6
Author
WJMZBMR
Source
2014 Multi-University Training Contest 4
题解:样例:可以赋值0 2,1 2,2 2,1 1,2 1,2 0。dp[i]:i转化为二进制,第一位表示和为1,第二位表示和为2……,二进制1表示有,0表示无。如i=3,二进制是11,表示有和为1,2的存在。下一个状态:next=(1<<(p-1))|i|(i<<k)&size。1、表示和为p的存在,2、i本身,3、有和为(i+p)存在。
代码:
#include<bits/stdc++.h>#define debug cout<<"aaa"<<endl#define mem(a,b) memset(a,b,sizeof(a))#define LL long long#define lson l,mid,root<<1#define rson mid+1,r,root<<1|1#define MIN_INT (-2147483647-1)#define MAX_INT 2147483647#define MAX_LL 9223372036854775807i64#define MIN_LL (-9223372036854775807i64-1)using namespace std;const int N = 100000 + 5;const int mod = 1000000000 + 7;int t,n,k,l,minn,v;LL dp[1<<21],ans;int main(){scanf("%d",&t);while(t--){int size,next;scanf("%d%d%d",&n,&k,&l);size=(1<<k)-1,minn=min(k,l),mem(dp,0),dp[0]=1,ans=0;for(int i=1;i<=n;i++){for(int j=size;j>=0;j--){if(dp[j]){v=dp[j];for(int p=1;p<=minn;p++){next=(1<<(p-1))|j|((j<<p)&size);dp[next]=(dp[next]+v)%mod;}if(k<l)dp[j]=(dp[j]+(LL)v*(l-k))%mod;}}}for(int i=0;i<=size;i++){if(i&(1<<(k-1))){ans=(ans+dp[i])%mod;}}printf("%lld\n",ans);}return 0;}
Our happy ending
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1275 Accepted Submission(s): 447
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.
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.
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
12 2 2
Sample Output
6
Author
WJMZBMR
Source
2014 Multi-University Training Contest 4
阅读全文
0 0
- HDU 4906 Our happy ending (状压DP)
- hdu 4906 Our happy ending(状压dp)
- HDU 4906 Our happy ending 状压DP
- HDU-4906 Our happy ending 状压DP
- HDU 4906 Our happy ending 状压DP
- hdu 4906 Our happy ending 状压dp
- hdu 4906 Our happy ending
- hdu 4906 Our happy ending (状态压缩dp)
- hdu 4906 Our happy ending 状态压缩dp
- hdu 4906 Our happy ending 状态压缩dp 较难
- hdu 4906 Our happy ending (多校第4场 )状压DP
- hdu4906 Our happy ending --- 状压dp
- hdu 4906——Our happy ending
- HDU 4906 Our happy ending 解题报告(递推)
- hdu4906 Our happy ending,状态压缩DP
- Our happy ending
- hdu4906Our happy ending 状压dp
- hdu 4906 Our happy ending 。神奇的状态转移方程,记录下
- 黑客叔叔(雨袭团)内部交流题(第一季1.0.2)
- js中的call和apply
- HDU 1197
- Hello Baidu Map
- Codeforces 833B
- hdu 4906 Our happy ending 状压dp
- TensorFlow基础知识6-可视化(TensorBoard)
- JAVA基础之方法概述及其方法重载
- AngularJs自定义指令详解
- 【最短路入门专题1】E
- 设计模式之观察者模式
- python-pandas的基本用法06
- 网络图片查看器
- react native仿微信PopupWindow效果