• HUNNU--湖师大--11409--Skill


    Skill

    Yasser is an Egyptian coach; he will be organizing a training camp in Jordan. At the end of camp, 

    Yasser was quiet amazed that the participants solved all of the hard problems he had prepared; so he 
    decided to give them one last challenge:
    Print the number of integers having N digits where the digits form a non decreasing sequence.
    Input Specification
    Input will start with T <= 100 number of test cases. Each test case consists of a single line having 
    integer N where 1 <= N <= 100000.
    Output Specification
    For each test case print on a separate line the number of valid sequences modulo 1000000007.
    Sample Input
    3
    2
    3

    4


    Sample Output
    55
    220

    715

       这题是想要暴力的弟弟们妹妹们,放弃治疗吧,看到没?输出都对10亿取模了,好吧,不啰嗦了,这个小题的搞法呢是一位一位去考虑,当然就是传说中的“打表”了,你想啊,题目要求的是非递减,所以我只要从少一位的里面所有数考虑,比如12,我要加一位(只说加最前面,其实一样的),要满足条件就只能是112和012了,快要搞不清了,直接上代码再喷口水吧

    #include <iostream>
    #define mod 1000000007
    using namespace std;
    int main (void)
    {
        int t,n,i,j,k,l,xx[10]={1,1,1,1,1,1,1,1,1,1},d[100001]={0,10};  //xx里面是最高位数字能有的数字数量,d就是要打的表
        for(i=2;i<100001;i++)
        {
            for(j=9;j>=0;j--)  //从大的向小的找,像我要加一位,当前最高位数字是9,那么我可以加9、8、7、6、5、4、3、2、1、0
            for(k=j-1;k>=0;k--)  //
    当然本身xx[j]就是保存了数据的,所以直接从j-1开始加
            xx[j]=(xx[j]+xx[k])%mod;  //要取模
            for(j=0;j<10;j++)  //把当前位数的结果装进表中
            d[i]=(d[i]+xx[j])%mod;
        }
        cin>>t;
        while(t--&&cin>>n)
        {
            cout<<d[n]<<endl;
        }
        return 0;
    }

       一两句话说不清楚,那就举例子好一点

    最高位数字  0  1  2  3  4  5  6  7  8  9

    1位:           1  1  1  1  1  1  1  1  1  1    //因为一位数的时候满足条件的只有0,1,2,3,4,5,6,7,8,9,每个数字在最高位只有一次

    2位:           1  2  3  4  5  6  7  8  9  10  //两位数我0开头的就是00,1开头的是10,11,2开头是20,21,22.....这下有头绪了没?--!2位的时候我只要看1位的时候最高位数字的个数,然后哪些是可以加上去的我就加上去,怎么样?是不是蛮哈皮的搞法?亲~~

  • 相关阅读:
    local_irq_disable和disable_irq的区别
    linux内核IDR机制详解【转】
    飞秋2013设置后无法保存配置问题
    windows 格式化D盘
    query 中 radio选中小技巧
    磁盘碎片整理
    服务器如何选择备案产品类型?
    虚拟主机需要备案吗?
    操作系统自带的截图工具无法保存问题
    CA210彩分仪校准步骤
  • 原文地址:https://www.cnblogs.com/suncoolcat/p/3358221.html
Copyright © 2020-2023  润新知