C - Remembering Strings

思路:最关键的一点是字符的个数比串的个数多。 然后就能状压啦。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PII pair<int, int>
#define y1 skldjfskldjg
#define y2 skldfjsklejg using namespace std; const int N = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ; int val[][], cost[][], state[][];
int dp[ << ], n, m;
char s[][];
int main() {
scanf("%d%d", &n, &m);
for(int i = ; i < n; i++) scanf("%s", s[i]);
for(int i = ; i < n; i++)
for(int j = ; j < m; j++)
scanf("%d", &cost[i][j]); for(int i = ; i < n; i++) {
for(int j = ; j < m; j++) {
int mx = ;
for(int k = ; k < n; k++) {
if(s[i][j] == s[k][j]) {
val[i][j] += cost[k][j];
mx = max(mx, cost[k][j]);
state[i][j] |= << k;
}
}
val[i][j] -= mx;
}
} int up = ( << n) - ;
memset(dp, inf, sizeof(dp)); dp[] = ;
for(int s = ; s < up; s++) {
for(int j = ; j < n; j++) {
if(!((s >> j)&)) {
for(int k = ; k < m; k++) {
dp[s|( << j)] = min(dp[s|( << j)], dp[s] + cost[j][k]);
dp[s|state[j][k]] = min(dp[s|state[j][k]], dp[s] + val[j][k]);
}
break;
}
}
}
printf("%d\n", dp[up]);
return ;
} /* */

Codeforces Round #302 (Div. 1) C - Remembering Strings 状压dp的更多相关文章

  1. Codeforces Round #302 (Div. 1) C. Remembering Strings DP

    C. Remembering Strings Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

  2. Codeforces Round #585 (Div. 2) E. Marbles (状压DP)

    题目:https://codeforc.es/contest/1215/problem/E 题意:给你一个序列,你可以交换相邻的两个数,要达到一个要求,所有相同的数都相邻,问你交换次数最少是多少 思路 ...

  3. Codeforces Round #585 (Div. 2) E. Marbles (状压DP),BZOJ大理石(同一道题)题解

    题意 林老师是一位大理石收藏家,他在家里收藏了n块各种颜色的大理石,第i块大理石的颜色为ai.但是林老师觉得这些石头在家里随意摆放太过凌乱,他希望把所有颜色相同的石头放在一起.换句话说,林老师需要对现 ...

  4. Codeforces 544E Remembering Strings 状压dp

    题目链接 题意: 给定n个长度均为m的字符串 以下n行给出字符串 以下n*m的矩阵表示把相应的字母改动成其它字母的花费. 问: 对于一个字符串,若它是easy to remembering 当 它存在 ...

  5. Codeforces Round #222 (Div. 1) C. Captains Mode 状压

    C. Captains Mode 题目连接: http://codeforces.com/contest/377/problem/C Description Kostya is a progamer ...

  6. Codeforces Round #297 (Div. 2) [ 折半 + 三进制状压 + map ]

    传送门 E. Anya and Cubes time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  7. Codeforces Round #321 (Div. 2) Kefa and Dishes 状压+spfa

    原题链接:http://codeforces.com/contest/580/problem/D 题意: 给你一些一个有向图,求不超过m步的情况下,能获得的最大权值和是多少,点不能重复走. 题解: 令 ...

  8. CF543C Remembering Strings 状压dp

    Code: #include <cstdio> #include <algorithm> #include <cstring> #define setIO(s) f ...

  9. 水题 Codeforces Round #302 (Div. 2) A Set of Strings

    题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...

随机推荐

  1. laravel 添加自定义 Provider 配置之后不生效的问题

    有可能是配置缓存导致的, 运行: php artisan config:clear 可清除配置缓存,配置缓存保存在 bootstrap/cache/config.php,可以直接去那文件夹看看是不是缓 ...

  2. lldb和gdb命令映射

    http://note.youdao.com/noteshare?id=45b6171a4a846f6b95db7d8211fbfb9c

  3. poj 3261 后缀数组 可重叠的 k 次最长重复子串

    Milk Patterns Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 16430   Accepted: 7252 Ca ...

  4. 手脱EXE32Pack v1.39

    1.PEID查壳 EXE32Pack v1.39 2.载入OD,先F8跟一下 0040A00C > 3BC0 cmp eax,eax ; //程序入口点 0040A00E je short st ...

  5. mysql命令修改登录用户密码

    方法1: 用SET PASSWORD命令 首先登录MySQL. 格式:mysql> set password for 用户名@localhost = password(‘新密码’); 例子:my ...

  6. 「Django」rest_framework学习系列-用户认证

    用户认证:1.项目下utils文件写auth.py文件 from rest_framework import exceptions from api import models from rest_f ...

  7. reset password for local admin on Windows2016 by Powershell

    上脚本吧,找半天 $password = "yourpassword" $pwd = $password | ConvertTo-SecureString -asPlainText ...

  8. JS自学大全

    JS是从上往下执行的 console.log();输出语句console.warn();错误提示语句 黄色三角形感叹号console.error();错误提示 红色圆Xalert();弹窗docume ...

  9. 数学&搜索:博弈论之极大极小搜索与alpha-beta减枝

    目的是寻找最优的方案使得自己能够利益最大化. 基本思想就是假设自己(A)足够聪明,总是能选择最有利于自己的方案,而对手(B)同样足够聪明,总会选择最不利A的方案 对抗搜索就是对于先手来说,取后手中状态 ...

  10. 【IDEA】 Can't Update No tracked branch configured for branch master or the branch doesn't exist. To make your branch track a remote branch call, for example, git branch --set-upstream-to origin/master

    IDEA点击GIT更新按钮时,报错如下: Can't UpdateNo tracked branch configured for branch master or the branch doesn' ...