hihoCoder 1251 Today Is a Rainy Day(暴力)
2015-11-16 15:41
489 查看
题目连接:hihoCoder 1251 Today Is a Rainy Day
解题思路
用一个6位6进制表示每个数对应的转换,用广搜预处理代价。代码
#include <cstdio> #include <cstring> #include <queue> #include <algorithm> using namespace std; const int maxn = 50005; const int inf = 0x3f3f3f3f; int dp[maxn]; int idx(int* c) { int ret = 0; for (int i = 0; i < 6; i++) ret = ret * 6 + c[i]; return ret; } void ridx(int s, int* c) { for (int i = 5; i >= 0; i--) { c[i] = s % 6; s /= 6; } } void presolve() { int c[10], t[10]; for (int i = 0; i < 6; i++) c[i] = i; int s = idx(c); memset(dp, inf, sizeof(dp)); dp[s] = 0; queue<int> que; que.push(s); while (!que.empty()) { s = que.front(); que.pop(); ridx(s, c); for (int i = 0; i < 6; i++) { for (int j = 0; j < 6; j++) { memcpy(t, c, sizeof(t)); for (int k = 0; k < 6; k++) if (t[k] == i) t[k] = j; int v = idx(t); if (dp[v] > dp[s] + 1) { dp[v] = dp[s] + 1; que.push(v); } } } } } int G[10][10], C[10]; char a[200], b[200]; int main () { presolve(); while (scanf("%s%s", a, b) == 2) { memset(G, 0, sizeof(G)); memset(C, 0, sizeof(C)); int n = strlen(a); for (int i = 0; i < n; i++) { int u = b[i] - '1', v = a[i] - '1'; C[u]++; G[u][v]++; } int ans = inf, t[10]; for (int s = 0; s < maxn; s++) { ridx(s, t); int tmp = dp[s]; for (int i = 0; i < 6; i++) tmp += C[i] - G[i][t[i]]; ans = min(ans, tmp); } printf("%d\n", ans); } return 0; }
相关文章推荐
- [论文笔记5]A Discriminatively Trained, Multiscale, Deformable Part Model
- raid 0,1,10,5特性
- 使用AIDL实现进程间的通信
- 【poj3831】Open-air shopping malls
- ArtifactTransferException: Failure to transfer com.sun.xml.bind:jaxb-xjc:jar:2.0.1 from http://192.1
- 转自 http://aikilis.tk/:0x3f3f3f3f作无穷大的精妙
- web.xml中<security-constraint>和四种认证类型
- process Launch Failed:failed to Get the Task for Process XXXX(解决方案)
- -canOpenURL: failed for URL: "" - error: "(null)" , iOS9 App传输安全 支持http 解决方案
- BaiduMap
- 小甲鱼第51讲:《__name__="__main__"、搜索路径和包》课后练习题
- 教授机器视物和理解——Facebook人工智能研究进展
- TurboMail反垃圾邮件系统提醒您辨别钓鱼邮件
- linux下设置线程优先级 http://blog.csdn.net/typhoonzb/article/details/4544278
- linker command failed with exit code 1错误产生原因分析
- 1 Introduction to AI
- Linux线程属性总结 http://blog.csdn.net/zsf8701/article/details/7842392
- HDU1021 Fibonacci Again
- poj 1422 Air Raid(最小路径覆盖)
- 安装inotify-tools,用inotifywait命令监听文件或目录的访问信息