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 ...
随机推荐
- VS2010 编译 sqlite3 生成动态库和链接库
如果想以dll的方式使用sqlite而新建空的dll工程,添加sqlite源文件,会发现能生成dll,但缺乏lib函数信息映射库,单独使用dll文件是比较麻烦的,而网上多数做法是通过lib.exe手动 ...
- fpga之显示字符串
//必须在有效区域下显示颜色才有颜色 显示字符可以在设定一个有效区域内显示 另加两个wire 求出新的x,ymodule vga_fpga( clk,rst_n, vga_b,vga_g,vga_r, ...
- android平台短视频技术之 视频编辑的经验分享.
android平台短视频技术之 视频编辑的经验分享. 提示一: 各位看官,这里分享的是视频编辑,即剪切/拼接/分离/合并/涂鸦/标记/叠加/滤镜等对视频的编辑操作.不是流媒体网络播放等功能,请注意. ...
- POJ 3139 Balancing the Scale
枚举. 看了这个方法:$http://www.cppblog.com/shiming413/archive/2008/12/21/29671.html$ 将数字归类的地方不能用$vector$,会超时 ...
- MySql 如何实现不同数据库同步【2个】
环境要求: Windows 操作系统 需要Mysql 3.23.15以后的版本. 假设数据库A为主机,数据库B为从机(A向B提供同步服务,即B中的数据来自A) A机器:IP=10.10.151.166 ...
- sulime text3
sublime text 3 详细说明--包括快捷键 sublime 插件安装 快捷键 sunlime (需要先安装package control,ctrl+shift+p,输入insall之后安装插 ...
- CoreAnimation的使用
一.CABasicAnimation CABasicAnimation *anim = [CABasicAnimation animation]; anim.keyPath = @"posi ...
- 导入导出Excel的Java工具类ExcelUtil
在编写ExcelUtil之前,在网上查了一些资料.java中用来处理Excel的第三方开源项目主要就是POI和JXL.poi功能强大,但是比较耗资源,对于大数据量的导入导出性能不是太好:jxl功能简单 ...
- ACboy needs your help hdu 分组背包问题
Description ACboy has N courses this term, and he plans to spend at most M days on study.Of course,t ...
- Objective-C Runtime 运行时之一:类与对象(转载)
Objective-C语言是一门动态语言,它将很多静态语言在编译和链接时期做的事放到了运行时来处理.这种动态语言的优势在于:我们写代码时更具灵活性,如我们可以把消息转发给我们想要的对象,或者随意交换一 ...