牛客网暑期ACM多校训练营(第六场)D-Bulbasaur

链接:https://www.nowcoder.com/acm/contest/144/D
来源:牛客网
 

题目描述

Silph company deployed a passenger flow analysis system in a clothing store that captures photos of human faces and photos of human bodies in real time.

In order to analyze the passenger flow better, the system will associate human faces with human bodies. In other words, there are some edges connecting faces with bodies. Each edge has a positive weight.

However, due to lack of precision and accuracy of the algorithms provided by this company, these associations may not be completely correct.

In a correct relationship, one human face can associate with multiple human bodies (one person may change multiple suits of clothes), but one human body cannot associate with multiple human faces.

Now Bulbasaur works as an intern at Silph company and the boss asks him to solve this problem.

Bulbasaur is supposed to find an association relationship, such that the sum of weights of the association edges is maximum.

输入描述:

The input starts with one line containing exactly one integer T, which is the number of test cases.

For each test case, the first line contains three integers n, m and k, indicating the number of face photos, the number of body photos, and the number of existing association edges, respectively.

Then followed by k lines, each consists of three integers ai, bi and ci, representing an edge weighted ci connecting the ai-th face photo with the bi-th body photo.

- 1 ≤ T ≤ 5.
- 1 ≤ n, m, k ≤105.
- 1 ≤ ai ≤ n.
- 1 ≤ bi ≤ m.
- 1 ≤ ci ≤ 109.
- .

输出描述:

For each test case, output one line containing "Case #x: y", where x is the test case number (starting from 1) and y is the maximum sum of weights of the association edges.

示例1

输入

1
2 3 3
1 2 1919
1 3 810
2 2 450

输出

Case #1: 2729

题意 :有n个人和m件衣服,每个人可以匹配多件衣服,每件衣服只能匹配一个人,求一个最大的匹配值

思路:暴力贪心,枚举每件衣服可能获得的最大值,直接加和就可以了。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>

using namespace std;

#define inf 0x3f3f3f3f

const int maxn=1e5+7;

int data[maxn];

int main()
{
    int t;
    int n,m,k;
    int ai,bi,ci;
    scanf("%d",&t);
    for (int cases = 1; cases <=t ; ++cases)
    {
        memset(data,0,sizeof(data));
        scanf("%d %d %d",&n,&m,&k);
        for (int i = 0; i < k; ++i)
        {
            scanf("%d %d %d",&ai,&bi,&ci);
            data[bi]=max(data[bi],ci);
        }
        long long ans=0;
        for (int i = 0; i < maxn; ++i) ans+=data[i];
        printf("Case #%d: %lld\n",cases,ans);
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/leper_gnome/article/details/81415351
今日推荐