和棋盘游戏一个类型的题目

矩阵转换为二分图最大匹配问题   每次碰撞气球都是一行或一列

#include<bits/stdc++.h>
using namespace std;
#define MAXI 105
int mp[MAXI][MAXI];
int used[MAXI];
int vis[MAXI];
int n,m;
int color[];
bool dfs(int x,int color)
{
for(int j=;j<=n;j++)
{
if(mp[x][j]==color&&!used[j])
{
used[j]=;
if(!vis[j]||dfs(vis[j],color))
{
vis[j]=x;
return true;
}
}
}
return false;
} int find1(int x)
{ int ans=;
memset(vis,,sizeof(vis));
for(int i=;i<=n;i++)
{
memset(used,,sizeof(used));
if(dfs(i,x))ans++;
}
return ans;
} int main()
{
int k;
while(scanf("%d%d",&n,&k)==&&(n||k))
{
int ans[MAXI];
memset(color,,sizeof(color));
memset(ans,,sizeof(ans)); for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
{
scanf("%d",&mp[i][j]);
color[mp[i][j]]=;
} int n=;
for(int i=;i<=;i++)
{
if(color[i])
{
if(k<find1(i))
ans[n++]=i;
}
} sort(ans,ans+n); if(n==)printf("-1\n");
else
{
for(int i=;i<n-;i++)
printf("%d ",ans[i]);
printf("%d\n",ans[n-]);
} }
return ;
}

50 years, 50 colors HDU的更多相关文章

  1. HDU 1498 50 years, 50 colors(最小点覆盖,坑称号)

    50 years, 50 colors Problem Description On Octorber 21st, HDU 50-year-celebration, 50-color balloons ...

  2. hdu 1498 50 years, 50 colors 最小点覆盖

    50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  3. hdu 1498 50 years, 50 colors(二分匹配_匈牙利算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1498 50 years, 50 colors Time Limit: 2000/1000 MS (Ja ...

  4. HDU——1498 50 years, 50 colors

    50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  5. 50 years, 50 colors

    50 years, 50 colors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...

  6. 50 years, 50 colors HDU - 1498(最小点覆盖或者说最小顶点匹配)

    On Octorber 21st, HDU 50-year-celebration, 50-color balloons floating around the campus, it's so nic ...

  7. HDU——T 1498 50 years, 50 colors

    http://acm.hdu.edu.cn/showproblem.php?pid=1498 Time Limit: 2000/1000 MS (Java/Others)    Memory Limi ...

  8. HDU 1498 50 years, 50 colors (行列匹配+最小顶点覆盖)

    题目:点击打开链接 题意:每个格子有不同颜色的气球用不同数字表示,每次可选某一行              或某一列来戳气球.每个人有K次机会.求最后哪些气球不能在             k次机会内 ...

  9. HDU 1498:50 years, 50 colors(二分图匹配)

    http://acm.hdu.edu.cn/showproblem.php?pid=1498 题意:给出一个 n*n 的矩阵,里面的数字代表一种颜色,每次能炸掉一排或者一列的相同颜色的气球,问有哪些颜 ...

  10. HDU 1498 50 years, 50 colors

    题目大意:给你一个 n*n 的矩阵,每个格子上对应着相应颜色的气球,每次你可以选择一行或一列的同种颜色的气球进行踩破,问你在K次这样的操作后,哪些颜色的气球是不可能被踩破完的. 题解:对于每一种颜色建 ...

随机推荐

  1. Spring点滴十:Spring自动装配(Autowire)

    在基于XML配置元数据,在bean的配置信息中我们可以使用<constructor-arg/>和<property/>属性来实现Spring的依赖注入.Spring 容器也可以 ...

  2. 【BZOJ1484】[HNOI2009]通往城堡之路 (贪心)

    [BZOJ1484][HNOI2009]通往城堡之路 (贪心) 题面 BZOJ 洛谷 题解 我大概是不会的. 大概是,首先把所有的人全部弄成最低的值,再一次次拔高一个后缀. 其他的全是抄的,百度随便找 ...

  3. KEIL5.25生成.bin文件步骤

    添加.bin文件转换工具 KEIL5的自带.bin文件转化工具在安装目录下:我的安装目录是C盘即,C:\Keil_v5\ARM\ARMCC\bin\fromelf.exe 添加格式为:[C:\Keil ...

  4. luogu1081 [NOIp2012]开车旅行 (STL::multiset+倍增)

    先用不管什么方法求出来从每个点出发,A走到哪.B走到哪(我写了一个很沙雕的STL) 然后把每个点拆成两个点,分别表示A从这里出发和B从这里出发,然后连边是要A连到B.B连到A.边长就是这次走的路径长度 ...

  5. bzoj1030: [JSOI2007]文本生成器(AC自动机+DP)

    第一次写这类题...懵 直接计算答案不好计算,所以补集转化求不合法的方案. 首先考虑朴素的DP,设$f(i, s)$表示前$i$个字符,字符串为$s$的方案数,且任意一个给定串都不存在$s$中. 我们 ...

  6. 解题:九省联考2018 IIIDX

    题面 我当时在考场上划水的时候好像乱搞搞了20pts,然后发现一堆同届的都写了55pts的贪心=.=??? 那就先说那55pts的贪心吧,这个现在看起来还是非常显然的,就是按题意来每一块是分属一个点的 ...

  7. bzoj4807 車

    题目大意: Description 众所周知,車是中国象棋中最厉害的一子之一,它能吃到同一行或同一列中的其他棋子.車跟車显然不能在一起打 起来,于是rly一天又借来了许多许多的車在棋盘上摆了起来……他 ...

  8. 数组初始化 memset fill

    #include <cstdio> #include <cstdlib> #include <cmath> #include <cstring> #in ...

  9. Java基础-hashMap原理剖析

    Java基础-hashMap原理剖析 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任.   一.什么是哈希(Hash) 答:Hash就是散列,即把对象打散.举个例子,有100000条数 ...

  10. [转载]Windows 8 VHD 概述与使用

    http://www.cnblogs.com/tonycody/archive/2012/11/30/2796858.html