|
发表于 2020-8-30 10:57:55
|
显示全部楼层
402
Process returned 0 (0x0) execution time : 0.219 s
Press any key to continue.
动态规划+记忆化搜索
设f(x)为x各位数阶乘之和
设集合
设len(x)为以x开始的链的不重复项数,则状态转移方程
- #include<iostream>
- #include<algorithm>
- using namespace std;
- const int f[] = {1,1,2,6,24,120,720,5040,40320,362880};
- const int len3[] = {169,1454,363601};
- const int len2[] = {871,872,45361,45362};
- const int len1[] = {0,1,2,145,40585};
- const int M = 1e6;
- int dp[M*10] = {0};
- int mx = 0;
- int f_sum(int x){
- int res = 0;
- if (x == 0) return 1;
- while(x){
- res += f[x % 10];
- x /= 10;
- }
- return res;
- }
- int len(int x){
- //mx = max(mx,x);
- int & ans = dp[x];
- if (ans) return ans;
- if (find(len3,len3 +3,x) != len3 +3) return ans = 3;
- if (find(len2,len2 +4,x) != len2 +4) return ans = 2;
- if (find(len1,len1 +5,x) != len1 +5) return ans = 1;
- return ans = len(f_sum(x)) + 1;
- }
- int main(){
- int cnt = 0;
- for (int i = 0;i <= M;i++)
- if (len(i) == 60) ++cnt;
- //cout << mx << endl;
- cout << cnt << endl;
- return 0;
- }
复制代码 |
|