lightoj 1037 Agent-47(状态压缩dp~)
来源:互联网 发布:温州领导干部网络学堂 编辑:程序博客网 时间:2024/05/28 06:07
也是一眼能看出状态压缩,然后就水过了
有个坑:
输入那个二维数组的时候,中间没有空格,所以要用输入字符串的方式进行转换!
#include <cmath>#include <cstdio>#include <cstring>#include <iostream>#define MAX_N 16#define INF 0x3f3f3f3fusing namespace std;int n;int health[MAX_N];int map[MAX_N][MAX_N];int dp[1 << MAX_N];char ss[MAX_N];int main(void) { int t; int Kase = 0; scanf("%d", &t); while (t--) { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &health[i]); for (int i = 0; i < n; i++) { scanf("%s", ss); for (int j = 0; j < n; j++) map[i][j] = ss[j] - '0'; } memset(dp, INF, sizeof(dp)); dp[0] = 0; for (int i = 0; i < n; i++) { dp[1 << i] = health[i]; } for (int s = 0; s < (1 << n); s++) { // i为未被射击到的 for (int i = 0; i < n; i++) { if (s & (1 << i)) continue; for (int j = 0; j < n; j++) { // j为已被射击到的 if (!((1 << j) & s)) continue; int shot = 0; if (map[j][i] <= 1) shot = health[i]; else shot = ceil(((double)health[i] / double(map[j][i]))); dp[(1 << i) | s] = min(dp[(1 << i) | s], dp[s] + shot); } } } printf("Case %d: %d\n", ++Kase, dp[(1 << n) - 1]); } return 0;}
阅读全文
0 0
- lightoj 1037 Agent-47(状态压缩dp~)
- Light 1037 - Agent 47 (状态压缩dp)
- lightoj 1037 - Agent 47 (状压DP)
- LightOJ 1037 - Agent 47(dp)
- LightOJ 1037 - Agent 47 (状压dp)
- LightOJ 1037 Agent 47(状压DP)
- Lightoj 1037 Agent 47(状压DP)
- lightoj 1011 (状态压缩dp)
- lightoj 1018 (状态压缩DP)
- Lightoj 1037 - Agent 47 详解(状压DP)
- LightOJ - 1037 Agent 47(状压DP)
- LightOJ 1037 - Agent 47(状压DP)
- lightoj 1037 - Agent 47 状压DP
- lightoj 1037 - Agent 47 【状压dp】
- lightoj 1086 状态压缩DP
- lightoj 1061 状态压缩DP
- lightoj 1119 状态压缩DP
- lightoj 1092 状态压缩DP
- HTTP和SOAP完全就是两个不同的协议
- Redis Cluster搭建记要
- 手写一个手机网页
- 小白Java笔记——第一个Java程序
- 【Oracle】下载11.2.0.4的地址
- lightoj 1037 Agent-47(状态压缩dp~)
- hdu
- Fragment+原生解析
- HTML——<a>标签的锚用法
- QQ侧滑效果
- 二进制、八进制和十六进制
- JsonUtil和JsonResult
- leetcode---implement-strstr---字符串
- python3结巴分词分行拆分统计词频