Code:

#include <cstdio>
#include <algorithm>
#include <cstring>
#define setIO(s) freopen(s".in","r",stdin)
#define inf (1<<22)
#define maxn 30
using namespace std;
char s[maxn][maxn];
int data[maxn][maxn],common[maxn][maxn],b[maxn][maxn],dp[inf],n,m;
int main() {
// setIO("input");
scanf("%d%d",&n,&m);
for(int i=0;i<n;++i) scanf("%s",s[i]);
for(int i=0;i<n;++i)
for(int j=0;j<m;++j)
scanf("%d",&data[i][j]);
for(int i=0;i<n;++i)
for(int j=0;j<m;++j) {
int sum=0,x=-inf;
for(int k=0;k<n;++k) {
if(s[k][j]==s[i][j]) {
sum+=data[k][j],x=max(x,data[k][j]);
common[i][j]|=(1<<k);
}
}
b[i][j]=sum-x;
}
memset(dp,0x3f,sizeof(dp)), dp[0]=0;
int re=(1<<n);
for(int i=0;i<re;++i)
for(int j=0;j<n;++j)
if((i&(1<<j))==0) {
for(int k=0;k<m;++k) {
dp[i|(1<<j)]=min(dp[i|(1<<j)], dp[i]+data[j][k]);
dp[i|common[j][k]]=min(dp[i|common[j][k]], dp[i]+b[j][k]);
}
}
printf("%d\n",dp[re-1]);
return 0;
}

  

CF543C Remembering Strings 状压dp的更多相关文章

  1. Codeforces 544E Remembering Strings 状压dp

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

  2. Codeforces Round #302 (Div. 1) C - Remembering Strings 状压dp

    C - Remembering Strings 思路:最关键的一点是字符的个数比串的个数多. 然后就能状压啦. #include<bits/stdc++.h> #define LL lon ...

  3. CF482C Game with Strings (状压DP+期望DP)

    题目大意:甲和乙玩游戏,甲给出n(n<=50)个等长的字符串(len<=20),然后甲选出其中一个字符串,乙随机询问该字符串某一位的字符(不会重复询问一个位置),求乙能确定该串是哪个字符串 ...

  4. [CF544E]Remembering Strings_状压dp

    E. Remembering Strings 题目大意: You have multiset of n strings of the same length, consisting of lowerc ...

  5. fzu2188 状压dp

    G - Simple String Problem Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  6. hdu 3247 AC自动+状压dp+bfs处理

    Resource Archiver Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 100000/100000 K (Java/Ot ...

  7. HDU3247 Resource Archiver —— AC自动机 + BFS最短路 + 状压DP

    题目链接:https://vjudge.net/problem/HDU-3247 Resource Archiver Time Limit: 20000/10000 MS (Java/Others)  ...

  8. FZU - 2218 Simple String Problem(状压dp)

    Simple String Problem Recently, you have found your interest in string theory. Here is an interestin ...

  9. HDU3247 Resource Archiver (AC自动机+spfa+状压DP)

    Great! Your new software is almost finished! The only thing left to do is archiving all your n resou ...

随机推荐

  1. Matlab——图形绘制——二维平面图形

    二维平面图形 hold on ————在已画好的图形上添加新的图形 plot 是绘制一维曲线的基本函数,但在使用此函数之前,我们需先定义曲线上每一点的x 及y 座标.下例可画出一条正弦曲线: > ...

  2. Discrete Mathematics and Its Applications | 1 CHAPTER The Foundations: Logic and Proofs | 1.2 Applications of Propositional Logic

    Translating English Sentences System Specifications Boolean Searches Logic Puzzles Logic Circuits

  3. SQL Server中的扩展事件学习系列

    SQL Server 扩展事件(Extented Events)从入门到进阶(1)——从SQL Trace到Extented Events SQL Server 扩展事件(Extented Event ...

  4. Eclipse使用jdbc连接MySql数据库报:java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: YES)

    在使用eclipse连接mysql数据库时报异常: java.sql.SQLException: Access denied for user 'root'@'localhost' (using pa ...

  5. angular 示例项目

    cnpm install 环境安装好后,快速创建一个新项目,如在D盘下新建一个angularProject项目,只要在本地目录下 ng new angularProject angularProjec ...

  6. Resharper 2019.1.1 破解

    本文链接:https://blog.csdn.net/qq_21361809/article/details/92423949                           Resharper ...

  7. k3 cloud在站点中新增用户

    1.进去金蝶云企业平台: 网址:https://cloud.kingdee.com/pt/ 2.进入控制台页面,我的产品下面选择添加用户 去cloud平台新增并同步用户注册信息 3.去管理中心更新用户 ...

  8. 奇葩的狐火浏览器border属性

    今天接到一个bug任务,客户反映火狐浏览器访问时某个商品楼层不显示商品.我立即打开我的火狐浏览器发现没有复现这个bug,后来经过一番折腾,才发现火狐浏览器缩放到90%时,商品楼层果然就消失了,而且每台 ...

  9. [七月挑选]优化hexo目录,使本地图片能显示出来

    title: 优化hexo目录,使本地图片能显示出来 查看了一下从此蜕变作者的Hexo中添加本地图片,提炼了一些能优化本地图片存放及编写是图片查看的问题. 1.修改配置文件_config.yml 里的 ...

  10. wpf textbox ctrl+enter事件

    <TextBox x:Name="xcontent" Text="sfasdf" Grid.Row="0" AcceptsReturn ...