Newcoder 144 D.Bulbasaur(水~)
阿新 • • 發佈:2018-12-10
Description
有個和個,給出種配對對應的權值,一個只能配一個,但一個可以配多個,問合法匹配的最大權值和
Input
第一行一整數表示用例組數,每組用例輸入三個整數,之後行每行輸入三個整數表示第個配第個的權值為
Output
輸出最大權值和
Sample Input
1 2 3 3 1 2 1919 1 3 810 2 2 450
Sample Output
Case #1: 2729
Solution
給每個配上權值最大的即可
Code
#include<cstdio> #include<algorithm> using namespace std; typedef long long ll; #define maxn 100005 int T,Case=1,n,m,k,mx[maxn]; int main() { scanf("%d",&T); while(T--) { scanf("%d%d%d",&n,&m,&k); for(int i=1;i<=m;i++)mx[i]=0; while(k--) { int a,b,c; scanf("%d%d%d",&a,&b,&c); mx[b]=max(mx[b],c); } ll ans=0; for(int i=1;i<=m;i++)ans+=mx[i]; printf("Case #%d: %lld\n",Case++,ans); } return 0; }