流水依依

希望朋友们有个好的身体,开开心心工作与学习。

博客园 首页 新随笔 联系 订阅 管理

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

The Second Jordanian Collegiate Programming Contest
Princess Sumaya University for Technology (PSUT)
November 17th
, 2012

   很好的一道数位DP。

#include <iostream>
#include <stdio.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <stack>
#include <math.h>
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std ;
typedef long long LL ;
LL dp[100008][10] ;
LL sum[100008] ;
const LL Mod=1000000007 ;
int main(){
   sum[1]=10 ;
   sum[2]=0 ;
   for(int i=0;i<=9;i++){
        dp[2][i]=10-i ;
        sum[2]+=dp[2][i] ;
   }
   for(int k=3;k<=100000;k++){
       LL sum_now=0 ;
       for(int i=9;i>=0;i--){
           dp[k][i]=sum_now+dp[k-1][i] ;
           if(dp[k][i]>=Mod)
              dp[k][i]%=Mod ;
           sum_now+=dp[k-1][i] ;
           if(sum_now>=Mod)
              sum_now%=Mod ;
       }
       sum[k]=0 ;
       for(int i=0;i<=9;i++){
           sum[k]+=dp[k][i] ;
           if(sum[k]>=Mod)
               sum[k]%=Mod ;
       }
   }
   int N ,T;
   cin>>T ;
   while(T--){
       cin>>N ;
       cout<<(sum[N]+Mod)%Mod<<endl ;
   }
   return 0 ;
}

 

 

 

 

 

posted on 2013-10-07 13:56  流水依依  阅读(513)  评论(0编辑  收藏  举报