UVA - 10981(dp ,map做内存类,仍没算出最大内存)
2015-03-25 13:42
190 查看
直接用map暴。
#include <algorithm> #include <iostream> #include <cstdio> #include <cstring> #include <string> #include <set> #include <vector> #include <queue> #include <map> using namespace std; typedef unsigned long long LLU; typedef long long LL; #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) const int maxn = 110; const int b[3][3]={ {1,1,0},{2,1,0},{0,2,2} }; int a[maxn],d[maxn][maxn][3],n,tar,path[maxn][maxn]; map<string,int> dp; map<string,string> pa; int dfs(string s){ if(dp.count(s)) return dp[s]; if(s.length()==1&&s[0]==tar+'a'){ return dp[s] = 1; } dp[s] = 0; for(int i=0;i<s.length()-1;i++){ string te; for(int j=0;j<i;j++) te.push_back(s[j]); te.push_back((char)(b[s[i]-'a'][s[i+1]-'a']+'a') ); for(int j=i+2;j<s.length();j++) te.push_back(s[j]); if(dfs(te)){ dp[s] = 1; pa[s] = te; return 1; } } return 0; } char s[maxn]; void print(string s){ printf("%s\n",s.c_str()); if(s.length() == 1){return ;} print(pa[s]); } int main() { int T; scanf("%d",&T); while(T--){ cin>>s; string ss = s; cin>>s; tar = s[0]-'a'; dp.clear(); pa.clear(); n = strlen(s); if(dfs(ss)) print(ss); else printf("None exist!\n"); if(T) printf("\n"); } return 0; }
相关文章推荐
- UVA-10074 最大子矩阵 DP
- URAL_1146/uva_108 最大子矩阵 DP 降维
- Party at Hali-Bula(UVA - 1220) 树形dp 最大独立集
- UVA-1331 Minimax Triangulation 区间dp 计算几何 三角剖分 最大三角形最小化
- UVA1220树上的dp(最大独立集)
- UVa 10755 - Garbage Heap 最大子块和 dp
- 100道动态规划——36 UVA 1220 Party at Hali-Bula 树形DP 最大独立集 思考欠妥
- UVa - 1220 - Party at Hali-Bula ( 树形DP 求最大独立集 )
- UVA - 507 - Jill Rides Again (dp最大子段和)
- UVa 11404 - Palindromic Subsequence(最大回文串,区间DP)
- UVA - 1484(树形dp,最大值最小值同时维护)
- dp uva1331最大面积最小三角形剖分
- UVA 1220 树形dp 最大独立集+状态标记
- uva 11691 - Allergy Test(DP+map)
- UVALive 3029 City Game 悬线法求最大子矩阵面积 dp
- POJ1964/UVALive 3029 -City Game -求最大子矩形-(暴力枚举/dp)
- UVa1642 Magical GCD-(最大权值子段和->map)
- UVA 1220 Party at Hali-Bula (树形dp--树的最大独立集)
- uva 1220 lrj-P282 最大独立集(树形dp)
- UVA - 607(简单dp,先用贪心确定最大,限定状态)