首页 技术 正文
技术 2022年11月12日
0 收藏 879 点赞 4,186 浏览 1434 个字
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
//head
#ifdef ONLINE_JUDGE
const int N = 1e6+10;
#else
const int N = 111;
#endifint n, m, mx, ans = INF;
char s[N];
int a[N], tmp[1<<17], f[1<<17];
int cst[1<<17], dp[1<<17];
int g[17][17];void dfs(int x) {
if (tmp[x]) return;
tmp[x] = 1;
for (int y=x; y; y^=y&-y) dfs(x^y&-y);
}
void dfs1(int x) {
if (f[x]||tmp[x]) return;
tmp[x] = 1;
ans = min(ans, cst[x]);
for (int y=x; y; y^=y&-y) dfs1(x^y&-y);
}int main() {
scanf("%d%d%s", &n, &m, s+1), mx=(1<<m)-1;
REP(i,1,n) ++cst[1<<(a[i]=s[i]-'a')];
REP(i,1,mx) cst[i]=cst[i^i&-i]+cst[i&-i];
REP(i,0,m-1) REP(j,0,m-1) scanf("%d", &g[i][j]);
REP(i,0,m-1) REP(j,0,m-1) if (!g[i][j]) {
int now = 0, pre = -1;
REP(k,1,n) {
if (a[k]==i||a[k]==j) {
if (a[k]==i&&pre==j||a[k]==j&&pre==i) {
dfs(mx^now);
}
now = 0, pre = a[k];
}
else now |= 1<<a[k];
}
int t = 1<<i|1<<j;
REP(k,0,mx) {
if ((k&t)==t) f[k] |= tmp[k];
tmp[k]=0;
}
}
dfs1(mx);
printf("%d\n", ans);
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,564
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,412
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,185
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905