HUNNU11409:Skill(数位DP)

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

 

题意:统计1~n位数中,从左到右的数位是按非递减排序的数有几个

思路:标准数位DP

 

#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

__int64 bit[1005];
__int64 dp[100005][10];//dp[i][j]存第i位放0~9的情况有多少
__int64 mod = 1000000007,n;

void solve(__int64 n)
{
    __int64 i,j,k,sum = 0;
    for(i = 1; i<=n; i++)//每位开始枚举
    {
        for(j = 0; j<=9; j++)//这一位的情况
        {
            for(k = 0; k<=j; k++)//前一位必须小于等于这一位
            {
                dp[i][j]+=dp[i-1][k];//这位放j,那么要加上前面那位放k的所有情况
                dp[i][j]%=mod;
            }
        }
    }
    for(j = 0; j<=9; j++)//末尾放0~9的所有情况加起来
    {
        sum+=dp[n][j];
        sum%=mod;
    }
}

int main()
{
    __int64 len,i,sum,j,t;
    memset(dp,0,sizeof(dp));
    dp[0][0] = 1;
    solve(100000);
    scanf("%I64d",&t);
    while(t--)
    {
        scanf("%I64d",&n);
        sum = 0;
        for(j = 0; j<=9; j++)
        {
            sum+=dp[n][j];
            sum%=mod;
        }
        printf("%I64d\n",sum);
    }

    return 0;
}


 

你可能感兴趣的:(dp,hunnu)