ZOJ2402 Lenny's Lucky Lotto List 简单DP
来源:互联网 发布:孔浩 java web 编辑:程序博客网 时间:2024/06/05 15:14
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. 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
#include<cstdio>#include<cstdlib>#include<iostream>#include<cmath>using namespace std;#define LL long long LL q[20][2100];void _dp(){for(int i=1;i<=2000;i++) q[1][i]=1;for(int i=2;i<=10;i++){ for(int j=pow(2,i-2);j<=2000;j++) { for(int k=j/2;k>=0;k--) q[i][j]+=q[i-1][k]; }};}int main(){int n;_dp();cin>>n; for(int i=1;i<=n;i++) { LL ans=0;int x,y;scanf("%d%d",&x,&y);for(int j=pow(2,x-1);j<=y;j++) ans+=q[x][j];printf("Case %d: n = %d, m = %d, # lists = %lld\n",i,x,y,ans); }return 0;}
- ZOJ2402 Lenny's Lucky Lotto List 简单DP
- ZOJ 2402 Lenny's Lucky Lotto Lists(简单DP)
- POJ 2193 Lenny's Lucky Lotto Lists(简单二维dp)
- poj 2193 Lenny's Lucky Lotto Lists 简单dp
- 1011. Lenny's Lucky Lotto
- pku2193 Lenny's Lucky Lotto Lists
- Scily 1011. Lenny's Lucky Lotto
- Sicily 1011 Lenny's Lucky Lotto
- poj 2193 Lenny's Lucky Lotto Lists
- [sicily online]1011. Lenny's Lucky Lotto
- Scily 1011. Lenny's Lucky Lotto
- sicily 1011. Lenny's Lucky Lotto
- Sicily 1011. Lenny's Lucky Lotto
- zoj 2402 - Lenny's Lucky Lotto Lists
- Sicily 1011.Lenny's Lucky Lotto
- POJ 2193 Lenny's Lucky Lotto Lists
- zoj 2402 Lenny's Lucky Lotto Lists
- Sicily 1011. Lenny's Lucky Lotto
- linux系统中errno对应的含义
- 代码干货 | Weex Android SDK源码分析
- SVN-cleanup-错误解决
- GBK到UTF8编码转换C++实现
- jquery 判断滚动位置
- ZOJ2402 Lenny's Lucky Lotto List 简单DP
- 一道面试题比较synchronized和读写锁
- activiti+myeclipse 安装插件
- 程序员常常接私活赚外快吗
- 饿了么项目开始---css3的flex布局,开发移动端界面
- Struts2
- logback.xml 配置Demo
- [RK3288][Android6.0] 调试笔记 --- home key触发启动launcher调用
- subplots与figure函数参数解释说明以及简单的使用脚本实例