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. Linux常用网络工具:批量主机服务扫描之nmap

    Linux下有很多强大网络扫描工具,网络扫描工具可以分为:主机扫描.主机服务扫描.路由扫描等. 之前已经写过常用的主机扫描和路由扫描工具,nmap支持批量主机扫描和主机服务扫描. nmap的安装直接使 ...

  2. (转)C++常见问题: 字符串分割函数 split

    http://www.cnblogs.com/dfcao/p/cpp-FAQ-split.html C++标准库里面没有字符分割函数split ,这可太不方便了,我已经遇到>3次如何对字符串快速 ...

  3. npm 的使用指南

    npm 使用指南 因为有写关于node.js的配置的博客,还有node和gulp的前端信息配置使用,其中有很多命令都用到了npm.所以这里要着重介绍一下npm. 1 npm介绍 npm(mode pa ...

  4. 2017北京国庆刷题Day5 afternoon

    期望得分:100+60+100=260 实际得分:0+60+40=100 设图中有m个环,每个环有si条边,有k条边不在环中 ans= (2^s1 -2)*( 2^s2 -2)* (2^s3 -2)… ...

  5. jieba文本分词,去除停用词,添加用户词

    import jieba from collections import Counter from wordcloud import WordCloud import matplotlib.pyplo ...

  6. 无聊js画了个菱形

    function repeat(str, count) { return count < 0 ? '' : (new Array(count)).join(str); } function di ...

  7. 赶快收藏!16款最流行的 JavaScript 框架

    下面为大家介绍 16款最流行的 JavaScript 框架,赶快收藏! 1. jQuery – Javascript框架 jQuery 是最流行的 JavaScript 框架,它简化了HTML 文档遍 ...

  8. 2017ACM暑期多校联合训练 - Team 6 1011 HDU 6106 Classes (容斥公式)

    题目链接 Problem Description The school set up three elective courses, assuming that these courses are A ...

  9. 6.MySQL简介

    MySQL简介 ·点击查看MySQL官方网站 ·MySQL是一个关系型数据库管理系统,由瑞典MySQLAB公司开发,后来被Sun公司收购,Sun公司后来又被Oracle公司收购,目前属于facle旗下 ...

  10. JS设计模式——4.继承(概念)

    类式继承 0.构造函数 一个简单的Person类 function Person(name){ this.name = name; } Person.prototype.getName = funct ...