sgu262:Symbol Recognition(状压DP)
来源:互联网 发布:会员积分软件免费版 编辑:程序博客网 时间:2024/06/05 04:46
题目大意:
分析:
AC code:
#include <cstdio>#include <cstring>#include <map>#define pii pair<int,int>#define mp make_pairusing namespace std;const int MAXK = 7;const int MAXN = 11;const int MAXS = 46660;const int INF = 0x3f;int n, m, k, s;int g[MAXK][MAXN][MAXN];int col[MAXN][MAXN];int f[MAXS], fr[MAXS], fx[MAXS], fy[MAXS];map<pii, int> S;int ans[MAXN][MAXN];void upd(int s, int x, int y){ int ts = s, add = f[s], tot = 0, ns = 0; pii sta[MAXK];S.clear(); for(int i = 0, j = 1; i < k; ++i, ts /= k, j *= k) { sta[i] = mp(ts%k, g[i][x][y]); if(!S.count(sta[i])) S[sta[i]] = tot++; ns += S[sta[i]]*j; } if(f[ns] > add+1) { f[ns] = add+1, fr[ns] = s; fx[ns] = x, fy[ns] = y; }}int main(){ #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif scanf("%d%d%d", &n, &m, &k); for(int i = 0; i < k; ++i) for(int p = 0; p < n; ++p) for(int q = 0; q < m; ++q) { scanf("%1d", &g[i][p][q]); col[p][q] |= g[i][p][q]; } s = 1; for(int i = 0; i < k; ++i) s *= k; memset(f, INF, sizeof f); f[0] = 0; for(int i = 0; i < n; ++i) for(int j = 0; j < m; ++j) if(col[i][j]) for(int p = 0; p < s; ++p) if(f[p] < INF) upd(p, i, j); int end = 0; for(int i = k-1; i >= 0; --i) end = end*k+i; printf("%d\n", f[end]); int now = end; while(now) { ans[fx[now]][fy[now]] = 1; now = fr[now]; } for(int i = 0; i < n; ++i) { for(int j = 0; j < m; ++j) printf("%d", ans[i][j]); puts(""); } #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout); #endif return 0;}
0 0
- sgu262:Symbol Recognition(状压DP)
- sgu-262 Symbol Recognition
- usaco 5.4 Character Recognition(统计DP)
- symbol
- symbol
- Symbol
- symbol
- Symbol
- Symbol
- Symbol
- Symbol
- hdu 4331 Image Recognition(DP+线段树)2012 Multi-University Training Contest 4
- Speech Recognition
- Face Recognition
- eMotion Recognition
- Character Recognition
- Subimage Recognition
- Image Recognition
- Android UI 优化——使用HierarchyViewer工具
- Android 网络通信框架Volley简介(Google IO 2013)
- 【OGG】OGG的单向DML复制配置(一)
- 异常处理
- 黑马程序员--指针(1)
- sgu262:Symbol Recognition(状压DP)
- hg转git的那些事
- 【福利来袭】扫描CSDN学院二维码,即送电子优惠券一张!
- SIP 之 imsdroid学习-----阿冬专栏
- Update curl on Android to resolve security problem cause by OpenSSL
- 20150611_OC之数组NSArray中函数操作
- 错误集-在IOS8中百度地图无法定位
- Python:各种编码简单总结
- "server tomcat v8.0 server at localhost failed to start"+"A child container failed during start"