题意:

有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. uinty3d使用ugui封装一个分页控件

    我们在显示数据时有的数据比较多,手机内存有限,我们不可能分配很多的控件来显示这些数据,分页是一个不错的选择.比如玩家交易行.我们现在封装一个自己简单的分页控件来显示玩家交易行. 分页控件的原理其实很简 ...

  2. Saltstack Master 配置文件详解

    #主配置 /etc/salt/master interface 默认值:0.0.0.0(所有的网络地址接口) 绑定到本地的某个网络地址接口 interface: 192.168.30.131 publ ...

  3. idea新建项目文件名为红色的解决办法

    Perference->version Control ->Directory添加项目路径,vcs选<none> 即可.

  4. retrofit2学习

    http://www.cnblogs.com/wondertwo/p/5838528.html  使用要点

  5. Java 彩色图转灰度图

    1. 方法1 BufferedImage grayImage = new BufferedImage(width, height, colorImage.TYPE_BYTE_GRAY); Graphi ...

  6. linux入侵控制与痕迹清理

    后门 (1)开机自动反弹shell (2)linux后门 Rookit 目前常用的有:t0rn /mafix/enyelkm 等 mafix rootkit Mafix是一款常用的轻量应用级别Root ...

  7. [转] windows 上用程序putty使用 ssh自动登录Linux(Ubuntu)

    需求: 在Win7电脑上使用putty(一种ssh客户端)连接Ubuntu 工具: puttygen.exe 和 putty.exe 第一步:生成密匙 运行puttygen.exe,选择需要的密匙类型 ...

  8. 连接到sql server 2008 TCP、IP出错

    1.点击 开始 --> 所有程序 --> Microsoft SQL Server2008 --> 配置工具-->SQL Server  configuration Manag ...

  9. 动态Order by

    ),) set @order='' ' select * from T_Table order by then ID end desc, then CreateTime end desc

  10. echarts样式修改

    本人是查看如下链接: http://down.admin5.com/demo/code_pop/cs/dsj/doc/example/themeDesigner.html# 图示很简洁明了.