CF543C Remembering Strings 状压dp
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的更多相关文章
- Codeforces 544E Remembering Strings 状压dp
题目链接 题意: 给定n个长度均为m的字符串 以下n行给出字符串 以下n*m的矩阵表示把相应的字母改动成其它字母的花费. 问: 对于一个字符串,若它是easy to remembering 当 它存在 ...
- Codeforces Round #302 (Div. 1) C - Remembering Strings 状压dp
C - Remembering Strings 思路:最关键的一点是字符的个数比串的个数多. 然后就能状压啦. #include<bits/stdc++.h> #define LL lon ...
- CF482C Game with Strings (状压DP+期望DP)
题目大意:甲和乙玩游戏,甲给出n(n<=50)个等长的字符串(len<=20),然后甲选出其中一个字符串,乙随机询问该字符串某一位的字符(不会重复询问一个位置),求乙能确定该串是哪个字符串 ...
- [CF544E]Remembering Strings_状压dp
E. Remembering Strings 题目大意: You have multiset of n strings of the same length, consisting of lowerc ...
- fzu2188 状压dp
G - Simple String Problem Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- hdu 3247 AC自动+状压dp+bfs处理
Resource Archiver Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 100000/100000 K (Java/Ot ...
- HDU3247 Resource Archiver —— AC自动机 + BFS最短路 + 状压DP
题目链接:https://vjudge.net/problem/HDU-3247 Resource Archiver Time Limit: 20000/10000 MS (Java/Others) ...
- FZU - 2218 Simple String Problem(状压dp)
Simple String Problem Recently, you have found your interest in string theory. Here is an interestin ...
- 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 ...
随机推荐
- Python Requests post方法中data与json参数问题
1.data参数 你想要发送一些编码为表单形式的数据——非常像一个 HTML 表单.要实现这个,只需简单地传递一个字典给 data 参数.你的数据字典在发出请求时会自动编码为表单形式,header默认 ...
- 【linux开发】ubuntu执行sudo apt-get update提示缺少公钥
ubuntu执行sudo apt-get update提示缺少公钥 提示信息如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 获取:1 http://arch ...
- MySql 性能优化之 Explain
MySQL 之 Explain 输出分析 背景 前面的文章写过 MySQL 的事务和锁,这篇文章我们来聊聊 MySQL 的 Explain,估计大家在工作或者面试中多多少少都会接触过这个.可能工作中实 ...
- Maximum Depth of Binary Tree(二叉树最大深度)
来源:https://leetcode.com/problems/maximum-depth-of-binary-tree Given a binary tree, find its maximum ...
- Nginx日志监控 使用 goaccess查看nginx日志
nginx日志监控 yum install goaccess 安装使用教程 goaccess access.log -o ../html/report.html --real-time-html ...
- eclipse中经常用到的修改菜单项
1.编写java程序时,书写一个类之后,要调用此类的某个方法时,点个点,此类的所有方法都会自动出现,然后再选择需要的那个方法即可: 2.鼠标放在一个类上面,关于此类的相关描述就会自动加载出来,要修改的 ...
- 通过Spark Streaming处理交易数据
Apache Spark 是加州大学伯克利分校的 AMPLabs 开发的开源分布式轻量级通用计算框架. 由于 Spark 基于内存设计,使得它拥有比 Hadoop 更高的性能(极端情况下可以达到 10 ...
- make the fence great again(dp 二维)
D. Make The Fence Great Again time limit per test 2 seconds memory limit per test 256 megabytes inpu ...
- MySQL explain,type分析(转)
问题:explain结果中的type字段代表什么意思? MySQL的官网解释非常简洁,只用了3个单词:连接类型(the join type).它描述了找到所需数据使用的扫描方式. 最为常见的扫描方式有 ...
- Delphi主消息循环研究(Application.Run和Application.Initialize执行后的情况)
Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; 第一步,貌似什么都不做,但如果提前定义I ...