zoukankan      html  css  js  c++  java
  • soj1011. Lenny's Lucky Lotto

    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 = 4 and = 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

    开个二维数组,动态规划,记住递推关系:f[i][x] = sum(f[i-1][j]) ,其中j = 1 to x/2
    代码如下:
     
    #include <iostream>
    #include <memory.h>
    using namespace std;
    //注意这里记得考虑精度问题,应选用unsigned long long,不然会WA
    unsigned long long qq[11][2001];
    
    int main()
    {
    	int num;
    	int count = 0;
    	cin >> num;
    	while(num--)
    	{
    		count++;
    		memset(qq,0,sizeof(qq));
    		int N,M;
    		cin >> N >> M;
    		int i,j,k;
    	    unsigned long long sum = 0;
    		for(i = 1;i <= M;i++)
    			qq[1][i] = 1;
    		for(i = 2;i <= N;i++)
    		{
    			for(j = 1;j <= M;j++)
    			{
    				for(k = 1;k <= j / 2;k++)
    					qq[i][j] += qq[i-1][k];
    			}
    		}
    		for(i = 1;i <= M;i++)
    			sum += qq[N][i];
    		cout << "Case " << count << ": n = " << N << ", m = " << M << ", # lists = " << sum << endl;
    	}
    	return 0;
    }
    
  • 相关阅读:
    [TC_SRM_466]DrawingBlackCrosses
    [POJ3254]Corn Fields
    [openjudge6043]哆啦A梦的时光机
    网络流 24 题汇总(LOJ 上只有 22 题???)
    Xadmin组件的url设计
    《今日简史》一、旧故事已然崩坏,新故事尚未构建
    《人类简史》二、认知革命——上帝之手的秘密
    ORM复习
    无拘无束的爱情
    使用代理导致IE host被修改问题的解决方案
  • 原文地址:https://www.cnblogs.com/sysu-blackbear/p/3226482.html
Copyright © 2011-2022 走看看