URAL 1009 K-based Numbers
题目:Click here
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int INF = 0x3f3f3f3f; 5 const int M = 3e5+3; 6 7 int n, k; 8 int dp[11][20][2]; // dp[i][j][k]表示i进制下j位数以k结尾的个数(k=0表示以0结尾;k=1表示不以0结尾) 9 int main() { 10 for( int i=2; i<=10; i++ ) { 11 dp[i][1][0] = 0; 12 dp[i][1][1] = i-1; 13 for( int j=2; j<=18-i; j++ ) { 14 dp[i][j][0] = dp[i][j-1][1]; 15 dp[i][j][1] = (dp[i][j-1][0]+dp[i][j-1][1])*(i-1); 16 } 17 } 18 while( ~scanf("%d%d", &n, &k ) ) { 19 printf("%d\n", dp[k][n][0]+dp[k][n][1] ); 20 } 21 return 0; 22 }