HDU5090 Game with Pearls

/*
HDU5090 Game with Pearls
http://acm.hdu.edu.cn/showproblem.php?pid=5090
匈牙利算法
 *
 */

#include<stdio.h>
#include<algorithm>
using namespace std;
const int Nmax=305;
int t,n,k,x,ans;
int match[Nmax],book[Nmax],map[Nmax][Nmax];
int init()
{
    ans=0;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            map[i][j]=0;
    for(int i=1;i<=n;i++)
        match[i]=book[i]=0;
}

int dfs(int u)
{
    for(int i=1;i<=n;i++)
    {
        if(map[i][u] && !book[i])
        {
            book[i]=1;
            if(!match[i] || dfs(match[i]))
            {
                match[i]=u;
                return 1;
            }
        }

    }
    return 0;
}

int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&k);
        init();
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&x);
            for(int j=x;j<=n;j+=k)
                map[j][i]=1;
        }
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++) book[j]=0;
            if(dfs(i))
                ans++;
        }
        if(ans==n)
            printf("Jerry\n");
        else
            printf("Tom\n");
    }
    return 0;
}
时间: 2024-10-19 08:15:56

HDU5090 Game with Pearls的相关文章

HDU5090——贪心——Game with Pearls

Problem Description Tom and Jerry are playing a game with tubes and pearls. The rule of the game is: 1) Tom and Jerry come up together with a number K. 2) Tom provides N tubes. Within each tube, there are several pearls. The number of pearls in each

Game with Pearls

Problem Description Tom and Jerry are playing a game with tubes and pearls. The rule of the game is:1) Tom and Jerry come up together with a number K. 2) Tom provides N tubes. Within each tube, there are several pearls. The number of pearls in each t

Hdoj 1300 Pearls 【DP】

Pearls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1699    Accepted Submission(s): 778 Problem Description In Pearlania everybody is fond of pearls. One company, called The Royal Pearl, pro

HDU 5090 Game with Pearls(二分匹配)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5090 Problem Description Tom and Jerry are playing a game with tubes and pearls. The rule of the game is: 1) Tom and Jerry come up together with a number K. 2) Tom provides N tubes. Within each tube, the

HDU - 5009 Paint Pearls(dp+双向链表优化)

Problem Description Lee has a string of n pearls. In the beginning, all the pearls have no color. He plans to color the pearls to make it more fascinating. He drew his ideal pattern of the string on a paper and asks for your help. In each operation,

HDU 5009 Paint Pearls(西安网络赛C题) dp+离散化+优化

转自:http://blog.csdn.net/accelerator_/article/details/39271751 吐血ac... 11668627 2014-09-16 22:15:24 Accepted 5009 1265MS 1980K 2290 B G++ czy   Paint Pearls Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Subm

Paint Pearls

Paint Pearls 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5009 dp+双向链表优化 看到题目,很自然地可以定义状态:dp[i]表示涂好a[0...i]的字符串,花费的最小代价. 状态转移方程:dp[i]=min(dp[i],dp[j]+num2),其中num=从a[j]到a[i]不同的数字个数. 时间复杂度为O(n2),对于n=50000的数据,明显会T. 于是,我们需要进行优化.注意到状态数无法化简,考虑优化转移复杂度. 当区间

hdu 5009 Paint Pearls (dp)

Problem Description Lee has a string of n pearls. In the beginning, all the pearls have no color. He plans to color the pearls to make it more fascinating. He drew his ideal pattern of the string on a paper and asks for your help. In each operation,

【POJ 1260】Pearls

[POJ 1260]Pearls dp问题 最近做背包做多了 一做动规就往背包想-- 这题其实也有点背包的意思(然而只是做背包做的看啥都像背包-- c件物品 有各自的数量a 和价值p 每进行一次交易的花费cost = (物品数+10)*价格 低价物品可以用高价一起购买 一次交易只能按照一种价值购买 初始dp[0] = 0 dp数组下标为物品件数 枚举物品种类 没枚举一种物品 遍历该物品之前物品量 假设之前有num件物品 当前枚举到的物品价值p 那么就要找到min(dp[k(0~num)] + (