Link:http://acm.hdu.edu.cn/showproblem.php?pid=1281
棋盘游戏
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2553 Accepted Submission(s): 1488
所以现在Gardon想让小希来解决一个更难的问题,在保证尽量多的“车”的前提下,棋盘里有些格子是可以避开的,也就是说,不在这些格子上放车,也可以保证尽量多的“车”被放下。但是某些格子若不放子,就无法保证放尽量多的“车”,这样的格子被称做重要点。Gardon想让小希算出有多少个这样的重要点,你能解决这个问题么?
第一行有三个数N、M、K(1<N,M<=100 1<K<=N*M),表示了棋盘的高、宽,以及可以放“车”的格子数目。接下来的K行描述了所有格子的信息:每行两个数X和Y,表示了这个格子在棋盘中的位置。
Board T have C important blanks for L chessmen.
3 3 4 1 2 1 3 2 1 2 2 3 3 4 1 2 1 3 2 1 3 2
Board 1 have 0 important blanks for 2 chessmen. Board 2 have 3 important blanks for 3 chessmen.
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=111;
int g[maxn][maxn],match[maxn],n,m,k;
bool vis[maxn];
bool dfs(int u)
{
for(int i=1;i<=n;i++)
{
if(!vis[i]&&g[u][i])
{
vis[i]=true;
if(match[i]==-1||dfs(match[i]))
{
match[i]=u;
return true;
}
}
}
return false;
}
int hangry()
{
int i,cnt;
memset(match,-1,sizeof(match));
cnt=0;
for(i=1;i<=n;i++)
{
memset(vis,false,sizeof(vis));
if(dfs(i))
{
cnt++;
}
}
return cnt;
}
int main()
{
int i,j,x,y,ans,anst,num,cas;
cas=0;
while(scanf("%d%d%d",&n,&m,&k)==3)
{
cas++;
memset(g,0,sizeof(g));
while(k--)
{
scanf("%d%d",&x,&y);
g[x][y]=1;
}
ans=hangry();
num=0;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
if(g[i][j])
{
g[i][j]=0;
anst=hangry();
if(anst<ans)
num++;
g[i][j]=1;
}
}
}
printf("Board %d have %d important blanks for %d chessmen.\n",cas,num,ans);
}
}
197



被折叠的 条评论
为什么被折叠?



