您的位置:首页 > 其它

sicily 1011. Lenny's Lucky Lotto

2015-05-14 13:12 369 查看
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

很简单的DP题目,其实一开始我是把dp
[m]当做n位最右边那位刚好为m来做的,这种做法是要累加的,然后公式是dp
[m]=dp
[2^n-1]+…+dp
[m-1]+dp[n-1][2^n-2]+…+dp[n-1][m/2],后来证明是错的,因为重复计算了,应该是dp
[m]=dp[n-1][2^n-2]+…+dp[n-1][m/2]。。。。。。。后来经过修正,不难得到dp
[m]=dp
[m-1]+dp
[m/2]。代表n位的最右边那位数小于等于m时的种类数,初始化条件是dp[1[i]=i,也很容易理解,最大可以放i的话,我可以放i种。一开始Wa了次,没想到是dp数组爆了,当n=7 m=2000就会爆,难怪过了样例还会WA,真是日了狗了,还有题目的C=0我也是醉了。好晚了,明天还要辅修,晚安。

#include <bits/stdc++.h>
using namespace std;

int t,n,m;
long long dp[200][2002];
void init(){
for(int i=1;i<=2000;i++)
dp[1][i]=i;

for(int i=2;i<=10;i++){
for(int j=pow(2,i-1);j<=2000;j++){
dp[i][j]+=dp[i][j-1]+dp[i-1][j/2];
}
}
}
int main(){
std::ios::sync_with_stdio(false);
init();
while(cin>>t&&t){
for(int i=1;i<=t;i++){
cin>>n>>m;
printf("Case %d: n = %d, m = %d, # lists = %lld\n",i,n,m,dp
[m]);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: