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;
    }
    
  • 相关阅读:
    css+javascript 仿outlook滑动菜单效果代码
    闭包
    AJAX式多数据源及节点异步加载树_meetrice
    CSS圆角边框表格
    Editplus 3.0 开发ext 教程
    IE右键快速转载到博客
    自已扩展EXT组件(Extending Ext Components)
    Ext程序规划入门
    EXT2联动选框 (Linked Combos Tutorial for Ext 2)
    EXT snippets 笔记
  • 原文地址:https://www.cnblogs.com/sysu-blackbear/p/3226482.html
Copyright © 2011-2022 走看看