UVALive 7352 Dance Recital
题意:
有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的更多相关文章
- ACM Dance Recital(dfs+剪枝)
The Production Manager of a dance company has been tasked with determining the cost for the seasonal ...
- UVALive 4222 Dance 模拟题
Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...
- UVALive - 2031 Dance Dance Revolution 三维dp
题目大意:有一个胖子在玩跳舞机.刚開始的位置在(0,0).跳舞机有四个方向键,上左下右分别相应1,2,3,4.如今有下面规则 1.假设从0位置移动到随意四个位置,消耗能量2 2.假设从非0位置跳到相邻 ...
- UVALive 4222 /HDU 2961 Dance 大模拟
Dance Problem Description For a dance to be proper in the Altered Culture of Machinema, it must abid ...
- BZOJ 1305: [CQOI2009]dance跳舞 二分+最大流
1305: [CQOI2009]dance跳舞 Description 一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲 ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- Malek Dance Club(递推)
Malek Dance Club time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
随机推荐
- python3.5 修改 IIS WEB.CONFIG的相关方法
#!/usr/bin/env python3.5 # -*- coding:utf8 -*- from xml.etree.ElementTree import ElementTree,Element ...
- Ubuntu环境openresty的安装
Ubuntu环境openresty的安装 相关库的安装 安装openresty需要的库 apt-get install libreadline-dev libncurses5-dev libpcre ...
- 敏捷开发(十)- Scrum每日例会
本文主要是为了检测你对SCRUM 评估会议的了解和使用程度, 通过本文你可以检测一下 1.你们的SCRUM 没人例会的过程和步骤 2.SCRUM 每日例会的输出结果一.会议目的 ...
- USACO 3.2 Magic Squares
Magic SquaresIOI'96 Following the success of the magic cube, Mr. Rubik invented its planar version, ...
- js中的错误检测
<!DOCTYPE html> <html> <body> <script> function myFunction() { try { var x=d ...
- 手机端rem自适应布局实例
首先要书写核心js代码,控制住页面的初始大小:我是以750px(即iPhone6)的标准,设置font-size:100px:<script> (function (doc, ...
- Xcode使用小结2
刷新时间慢的时候用timer定时器 以下内容为借用,作者:FlyElephant出处:http://www.cnblogs.com/xiaofeixiang iOS开发-NSOperation与GCD ...
- out和ref之间的区别
首先:两者都是按引用传递的,使用后都将改变原来参数的数值. 其次:ref可以把参数的数值传递进函数,但是out是要把参数清空,就是说你无法把一个数值从out传递进去的,out进去后,参数的数值为空,所 ...
- Jdk 1.8*安装并配置
转载自:http://www.cnblogs.com/zlslch/p/5658399.html 简单说下,jdk1.8*的下载,见http://www.cnblogs.com/zlslch/p/5 ...
- win8,win10安装mysql
以管理员身份进到命令窗口后,找到要安装的文件,执行msiexec /package mysql-installer-community-5.7.16.0.msi 回车即可