URAL 1012. K-based Numbers. Version 2

和1009一样,只不过需要用大数~~!!

 

#include <stdio.h> #include <stdlib.h> #include <string.h> #include <iostream> #include <algorithm> #include <queue> #include <stack> #include <math.h> using namespace std; const int MAX = 1010; int dp[20][200][MAX]; int len[20][200]; int main() { int n,k; memset(dp,0,sizeof(dp)); for(int i=2; i<=10; i++) { len[i][1] = len[i][2] = 1; dp[i][1][0] = i-1; dp[i][2][0] = (i-1)*i; } for(int i=2; i<=10; i++) for(int k=3; k<=180; k++) { int mlen = max(len[i][k-1],len[i][k-2]); for(int j=0; j<mlen; j++) { dp[i][k][j] += (i-1)*(dp[i][k-1][j] + dp[i][k-2][j]); if( dp[i][k][j] >= 10 ) { dp[i][k][j+1] += dp[i][k][j]/10; dp[i][k][j] %= 10; } } int j = mlen; if( dp[i][k][j] ) j++; while( dp[i][k][j] >= 10 ) { dp[i][k][j+1] += dp[i][k][j]/10; dp[i][k][j] %= 10; j++; } len[i][k] = j; } while( ~scanf("%d%d",&n,&k) ) { for(int i=len[k][n]-1; i>=0; i--) printf("%d",dp[k][n][i]); printf("/n"); } return 0; }

你可能感兴趣的:(URAL 1012. K-based Numbers. Version 2)