题意:

有n种舞蹈要跳 每种舞蹈需要每一行字符串所对应的那些人

如果一个人连着跳两个舞蹈 那么需要一个quick change

问需要的最少quick changes是多少

思路:

假期的题 又拿出来做一遍……

范围很感人10*26 这不暴力搜一发还等啥呢……

 /* ***********************************************
Author :Sun Yuefeng
Created Time :2016/10/16 20:17:34
File Name :A.cpp
************************************************ */ #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#define M(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=;
const int inf=0x3f3f3f3f; int n,sum,ans; char dance[][maxn];
int match[maxn][maxn];
int way[];
bool vis[maxn]; int solve(int x,int y){ //看两个舞蹈有几个人重复了
int sum=;
int lenx=strlen(dance[x]);
int leny=strlen(dance[y]);
for(int i=;i<lenx;i++)
for(int j=;j<leny;j++)
sum+=(dance[x][i]==dance[y][j]);
return sum;
} void dfs(int x){ //强行遍历
if(x>n){
if(sum<ans) ans=sum;
return ;
}
for(int i=;i<=n;i++){ //遍历部分
if(!vis[i]){
way[x]=i;
vis[i]=true;
sum+=match[way[x-]][i];
dfs(x+);
sum-=match[way[x-]][i];
vis[i]=false;
}
}
} int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(~scanf("%d",&n)){
getchar();
M(vis,false),M(match,),M(way,);
for(int i=;i<=n;i++)
scanf("%s",dance[i]);
for(int i=;i<=n;i++){
for(int j=;j<=n;j++){
if(i!=j)
match[i][j]=match[j][i]=solve(i,j); //预处理匹配状况
}
}
ans=inf; //初始化ans sum
sum=;
dfs(); //搜索
printf("%d\n",ans); }
return ;
}
/* 5
ABC
ABEF
DEF
ABCDE
FGH
6
BDE
FGH
DEF
ABC
BDE
ABEF
4
XYZ
XYZ
ABYZ
Z */

UVALive 7352 Dance Recital的更多相关文章

  1. ACM Dance Recital(dfs+剪枝)

    The Production Manager of a dance company has been tasked with determining the cost for the seasonal ...

  2. UVALive 4222 Dance 模拟题

    Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...

  3. UVALive - 2031 Dance Dance Revolution 三维dp

    题目大意:有一个胖子在玩跳舞机.刚開始的位置在(0,0).跳舞机有四个方向键,上左下右分别相应1,2,3,4.如今有下面规则 1.假设从0位置移动到随意四个位置,消耗能量2 2.假设从非0位置跳到相邻 ...

  4. UVALive 4222 /HDU 2961 Dance 大模拟

    Dance Problem Description For a dance to be proper in the Altered Culture of Machinema, it must abid ...

  5. BZOJ 1305: [CQOI2009]dance跳舞 二分+最大流

    1305: [CQOI2009]dance跳舞 Description 一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲 ...

  6. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  7. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  8. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  9. Malek Dance Club(递推)

    Malek Dance Club time limit per test 1 second memory limit per test 256 megabytes input standard inp ...

随机推荐

  1. Java 后台sql注入

    JdbcTemplate.update(sql, ArrayList.toArray()) Connection conn = null; PreparedStatement ps = null; c ...

  2. mybatis分页控件

    https://my.oschina.net/miemiedev/blog/135516

  3. OBJECT-ORIENTED

  4. 浏览器的云加速可能导致IP统计异常

    前段时间弄个流量统计相关的东西,请求展示图片时根据请求的IP进行 md5 签名生成点击链接的验证参数,结果发现一个莫名其妙的问题 发现点击日志中有一小部分点击的IP居然不一致,如果是开放给别人用可能存 ...

  5. CodeForces 685B Kay and Snowflake

    树的重心,树形$dp$. 记录以$x$为$root$的子树的节点个数为$sz[x]$,重儿子为$son[x]$,重心为$ans[x]$. 首先要知道一个结论:以$x$为$root$的子树的重心$ans ...

  6. CodeForces 340E Iahub and Permutations

    容斥原理,组合数. 找出有$cnt$个数字还有没放,那么总方案数就是$cnt!$. 总方案数里面包含了正确的和非正确的,我们需要将非正确的删去. 先删去$1$个数字$a[i]=i$的情况,发现会多删, ...

  7. JUnit——(二)注解

    1. 两种错误:Error和Failure Error是代码错误 @Test publicvoid testAdd() { int z=new T().add(5,3); assertEquals(8 ...

  8. Mac OS启动服务优化高级篇(launchd tuning)

    Mac下的启动服务主要有三个地方可配置:1,系统偏好设置->帐户->登陆项2,/System/Library/StartupItems 和 /Library/StartupItems/3, ...

  9. VMware虚拟机服务的vmware-hostd自动启动和停止

    安装了虚拟机 任务管理器会出现vmware-hostd.exe  占用了80端口,导致xampp打不开,所以就想关闭vmware,解决方案如下: 开始——运行——services.msc,找到VM打头 ...

  10. bzDemo

    <Public> <property name="Types"> <get/> </property> <method nam ...