Codeforces Round #302 (Div. 1) C - Remembering Strings 状压dp
思路:最关键的一点是字符的个数比串的个数多。 然后就能状压啦。
#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的更多相关文章
- 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 ...
- Codeforces Round #585 (Div. 2) E. Marbles (状压DP)
题目:https://codeforc.es/contest/1215/problem/E 题意:给你一个序列,你可以交换相邻的两个数,要达到一个要求,所有相同的数都相邻,问你交换次数最少是多少 思路 ...
- Codeforces Round #585 (Div. 2) E. Marbles (状压DP),BZOJ大理石(同一道题)题解
题意 林老师是一位大理石收藏家,他在家里收藏了n块各种颜色的大理石,第i块大理石的颜色为ai.但是林老师觉得这些石头在家里随意摆放太过凌乱,他希望把所有颜色相同的石头放在一起.换句话说,林老师需要对现 ...
- Codeforces 544E Remembering Strings 状压dp
题目链接 题意: 给定n个长度均为m的字符串 以下n行给出字符串 以下n*m的矩阵表示把相应的字母改动成其它字母的花费. 问: 对于一个字符串,若它是easy to remembering 当 它存在 ...
- Codeforces Round #222 (Div. 1) C. Captains Mode 状压
C. Captains Mode 题目连接: http://codeforces.com/contest/377/problem/C Description Kostya is a progamer ...
- Codeforces Round #297 (Div. 2) [ 折半 + 三进制状压 + map ]
传送门 E. Anya and Cubes time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #321 (Div. 2) Kefa and Dishes 状压+spfa
原题链接:http://codeforces.com/contest/580/problem/D 题意: 给你一些一个有向图,求不超过m步的情况下,能获得的最大权值和是多少,点不能重复走. 题解: 令 ...
- CF543C Remembering Strings 状压dp
Code: #include <cstdio> #include <algorithm> #include <cstring> #define setIO(s) f ...
- 水题 Codeforces Round #302 (Div. 2) A Set of Strings
题目传送门 /* 题意:一个字符串分割成k段,每段开头字母不相同 水题:记录每个字母出现的次数,每一次分割把首字母的次数降为0,最后一段直接全部输出 */ #include <cstdio> ...
随机推荐
- vue添加属性绑定
html <div id="app-2"> <span v-bind:title="message"> 鼠标悬停几秒钟查看此处动态绑定的 ...
- c++构造是否要加大括号
笔者被这个问题困扰良久,终于下决心看个究竟.废话不多说,先上结论: 如果对象是原生类型,加大括号会保证生成对象被初始化(一般是0) 如果对象非原生类型,加大括号或者不加,效果是一样的,都会执行该类的默 ...
- poj 3764 字典树
The xor-longest Path Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 7332 Accepted: 1 ...
- mysql cpu 占用高
vi /etc/my.cnf [mysqld]tmp_table_size=200M mysql> show global status like ‘created_tmp%‘; +—————— ...
- maven 依赖、聚合和继承 (转)
Maven 插件和仓库 Maven 本质上是一个插件框架,它的核心并不执行任何具体的构建任务,仅仅定义了抽象的生命周期,所有这些任务都交给插件来完成的.每个插件都能完成至少一个任务,每个任务即是一个功 ...
- poi对excel的操作(二)
二.进阶的对象 1.CellType 枚举类 单元格类型 CellType.STRING---文本型 等 如何是指单元格类型:cell.setCellType(CellType.STRING) 2.C ...
- Debian9(8)下python3和python2同时安装如何使用pip
在bash下Python会调用python2.x python3会调用python3.x 如果使用pip install命令安装模块会安装python2的模块. 而python3的pip命令使用的是p ...
- Atcoder #014 agc014_C BFS
LINK 题意:给定起点和最大操作次数$k$,地图'#'为上锁房间, 每次可以走$k$步,并任意解锁$k$个房间,问到达地图边界的最小次数. 思路:其实上锁与否并没有关系,因为先把$k$步走的次数用完 ...
- 26 THINGS I LEARNED IN THE DEEP LEARNING SUMMER SCHOOL
26 THINGS I LEARNED IN THE DEEP LEARNING SUMMER SCHOOL In the beginning of August I got the chance t ...
- .NET面试题系列(二)GC
序言 对象生存期 Phone item=new Phone() 在C#中,创建对象使用的是new关键字. 要注意的是new操作返回的并不是对象本身,而是对象的一个引用(Reference). 如果使用 ...