sicily 1011. Lenny's Lucky Lotto
来源:互联网 发布:tcl王牌液晶网络电视 编辑:程序博客网 时间:2024/06/05 10:40
1011. Lenny's Lucky Lotto
Constraints
Time Limit: 1 secs, Memory Limit: 32 MB
Description
Lenny likes to play the game of lotto. In the lotto game, he picks a list of N unique numbers in the range from 1 to M. If his list matches the list of numbers that are drawn, he wins the big prize.
Lenny has a scheme that he thinks is likely to be lucky. He likes to choose his list so that each number in it is at least twice as large as the one before it. So, for example, if N = 4 and M = 10, then the possible lucky lists Lenny could like are:
1 2 4 8
1 2 4 9
1 2 4 10
1 2 5 10
Thus Lenny has four lists from which to choose.
Your job, given N and M, is to determine from how many lucky lists Lenny can choose.
Input
There will be multiple cases to consider from input. The first input will be a number C (0 < C <= 50) indicating how many cases with which you will deal. Following this number will be pairs of integers giving values for N and M, in that order. You are guaranteed that 1 <= N <= 10, 1 <= M <= 2000, and N <= M. Each N M pair will occur on a line of its own. N and M will be separated by a single space.
Output
For each case display a line containing the case number (starting with 1 and increasing sequentially), the input values for N and M, and the number of lucky lists meeting Lenny’s requirements. The desired format is illustrated in the sample shown below.
Sample Input
3
4 10
2 20
2 200
Sample Output
Case 1: n = 4, m = 10, # lists = 4
Case 2: n = 2, m = 20, # lists = 100
Case 3: n = 2, m = 200, # lists = 10000
题意解析:给定n和m,在整数1~m中选出n个数a1~an,满足条件:1<=a[i]<=m且a[i+1]>=a[i]*2,的序列有多少种。
思路:设dp[i][j]表示长度为i的序列,以j结尾.
初始状态是dp[1][j]=1(1<=j<=m);
对于2<=i<=n,dp[i][j]=sum(dp[i-1][k]),1<=k<=j/2,表示长度为i,以j结尾的序列可能数等于 长度为i-1,以小于等于j/2结尾的序列可能数的和。
最后所求的就是sum(dp[n][i]),1<=i<=m.
代码如下:
#include<iostream>#include<cstring>using namespace std;const int MAXN=11;const int MAXM=2001;long long dp[MAXN][MAXM];int main(){ int t,n,m; cin>>t; int cnt=1; while(t--) { cin>>n>>m; memset(dp,0,sizeof(dp)); for(int i=1;i<=m;i++) dp[1][i]=1; for(int i=2;i<=n;i++) { for(int j=1;j<=m;j++) { for(int k=1;k<=j/2;k++) { dp[i][j]+=dp[i-1][k]; } } } long long sum=0; for(int i=1;i<=m;i++) { sum+=dp[n][i]; } cout<<"Case "<<cnt<<": n = "<<n<<", m = "<<m<<", # lists = "<<sum<<endl; cnt++; } return 0;}
- [sicily online]1011. Lenny's Lucky Lotto
- sicily 1011. Lenny's Lucky Lotto
- Sicily 1011. Lenny's Lucky Lotto
- Sicily 1011.Lenny's Lucky Lotto
- Sicily 1011. Lenny's Lucky Lotto
- sicily 1011. Lenny's Lucky Lotto
- sicily 1011. Lenny's Lucky Lotto
- Sicily 1011. Lenny's Lucky Lotto
- Sicily 1011 Lenny's Lucky Lotto
- 1011. Lenny's Lucky Lotto
- Scily 1011. Lenny's Lucky Lotto
- Scily 1011. Lenny's Lucky Lotto
- pku2193 Lenny's Lucky Lotto Lists
- poj 2193 Lenny's Lucky Lotto Lists
- zoj 2402 - Lenny's Lucky Lotto Lists
- POJ 2193 Lenny's Lucky Lotto Lists
- zoj 2402 Lenny's Lucky Lotto Lists
- ZOJ 2402 Lenny's Lucky Lotto Lists(简单DP)
- 敏捷开发绩效管理之十一:如何提高人员可用率?
- mapreduce top K实现
- 单链表的逆置
- 10条网站易用性设计改进技巧
- Unity 一段简单的AI
- sicily 1011. Lenny's Lucky Lotto
- Android单元测试
- JavaScript基础-Array
- 计算机会议排名:Computer Science Conference Rankings 转帖
- jQuery插件开发的模式和结构
- 关于模式对话框与非模式对话框释放资源的小总结
- 一步步学算法(算法题解)---3
- HTC DesireHD G10 完美root
- HTML实体符号代码速查表