标签:ring def fine div amp name cpp ios efi
嗯没错,最近和汉诺塔有仇,继续水一波汉诺塔IV
#include<iostream> #include<cstring> #define LL long long #define N 30 using namespace std; LL f[4][4][4][N]; LL solve(int a,int b,int c,int n,int &all){ if(n == 0) return 0; if(f[a][b][c][n]) return f[a][b][c][n]; if(n == all){ return f[a][b][c][n] = solve(a,c,b,n-1,all) + 2 + solve(c,b,a,n-1,all); } else if(n == 1){ if(a == 2 || b == 2) return f[a][b][c][n] = 1; else return f[a][b][c][n] = 2; } else if(a == 2){ return f[a][b][c][n] = solve(a,c,b,n-1,all) + 1 + solve(c,a,b,n-1,all) + solve(a,b,c,n-1,all); } else if(b == 2){ return f[a][b][c][n] = solve(a,b,c,n-1,all) + solve(b,c,a,n-1,all) + 1 + solve(c,b,a,n-1,all); } else{ return f[a][b][c][n] = solve(a,c,b,n-1,all) + solve(c,b,a,n-1,all) + 1 + solve(b,c,a,n-1,all) + solve(c,a,b,n-1,all) + 1 + solve(a,c,b,n-1,all) + solve(c,b,a,n-1,all); } } int main(){ int n,T; cin >> T; while(T--){ cin >> n; cout << solve(1,3,2,n,n) << endl; memset(f,0,sizeof(f)); } return 0; }
感觉和III没啥区别嗯。。。
标签:ring def fine div amp name cpp ios efi
原文地址:http://www.cnblogs.com/woodenhead/p/7992172.html