BZOJ 5248: [2018多省省队联测]一双木棋(对抗搜…
2018-06-17 20:36:57来源:未知 阅读 ()
Submit: 439 Solved: 379
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
2 7 3
9 1 2
3 7 2
2 3 1
Sample Output
HINT
Source
用$now[i]$表示第$i$行已经放了$now[i]$个棋子
爆搜之后发现状态数很小
因此用map记忆化一下就好
#include<cstdio> #include<algorithm> #include<cstring> #include<map> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/hash_policy.hpp> #define LL long long using namespace std; using namespace __gnu_pbds; const int MAXN = 11, INF = 1e9 + 10, base = 12; inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } int N, M; int A[MAXN][MAXN], B[MAXN][MAXN]; cc_hash_table<LL, int>mp; int now[MAXN]; LL gethash() { LL x = 0; for(int i = 1; i <= N; i++) x = x * base + now[i]; return x; } void push(LL x) { for(int i = N; i >= 1; i--) now[i] = x % base, x /= base; } int getnext() { int x = 0; for(int i = 1; i <= N; i++) x += now[i]; return x & 1; } int dfs(LL sta) { if(mp.find(sta) != mp.end()) return mp[sta]; push(sta); bool type = getnext(); int ans = !type ? -INF : INF; for(int i = 1; i <= N; i++) { if(now[i] < now[i - 1]) { now[i]++; LL nxt = gethash(); int val = dfs(nxt); ans = !type ? max(ans, val + A[i][now[i]]) : min(ans, val - B[i][now[i]]); now[i]--; } } return mp[sta] = ans; } main() { #ifdef WIN32 freopen("a.in", "r", stdin); //freopen("a.out", "w", stdout); #else freopen("chess2018.in", "r", stdin); freopen("chess2018.out", "w", stdout); #endif N = read(); M = read(); for(int i = 1; i <= N; i++) for(int j = 1; j <= M; j++) A[i][j] = read(); for(int i = 1; i <= N; i++) for(int j = 1; j <= M; j++) B[i][j] = read(); for(int i = 0; i <= N; i++) now[i] = M; mp[gethash()] = 0; dfs(0); printf("%d", mp[0]); }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- bzoj3569 DZY Loves Chinese II 2020-05-25
- bzoj4036 [HAOI2015]按位或 2020-04-26
- 「BZOJ4173」数学 2020-01-15
- bzoj3944 Sum 2019-12-25
- Noip2018Day1T3 赛道修建 2019-09-30
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash