input | output |
---|---|
2 10 |
90 |
AC代码:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cmath> #define LL long long using namespace std; int n, k; LL dp[55];//dp[i]表示位数为i时可以组成的数的个数,注意0在这里可以看做0位数 int main() { while(scanf("%d %d", &n, &k) != EOF) { memset(dp, 0, sizeof(dp)); dp[1] = k - 1; dp[2] = (k - 1) * k; for(int i = 3; i <= n; i++) { dp[i] = (k - 1) * (dp[i - 1] + dp[i - 2]); } cout << dp[n] <<endl; } return 0; }
URAL - 1009 - K-based Numbers (简单DP)
原文地址:http://blog.csdn.net/u014355480/article/details/44731071