Breaking news! A Russian billionaire has bought a yet undisclosed NBA team. He's planning to invest huge effort and money into making that team the best. And in fact he's been very specific about the expected result: the first place.
Being his advisor, you need to determine whether it's possible for your team to finish first in its division or not.
More formally, the NBA regular season is organized as follows: all teams play some games, in each game one team wins and one team loses. Teams are grouped into divisions, some games are between the teams in the same division, and some are between the
teams in different divisions.
Given the current score and the total number of remaining games for each team of your division, and the number of remaining games between each pair of teams in your division, determine if it's possible for your team to score at least as much wins as any
other team in your division.
The second line of input contains N integers w1, w2,..., wN, where wi is the total number of games that ith team has won to the moment.
The third line of input contains N integers r1, r2,..., rN, where ri is the total number of remaining games for the ith team (including the games inside the division).
The next N lines contain N integers each. The jth integer in the ith line of those contains aij — the number of games remaining between teams i and j. It is always true that aij=ajiand aii=0, for all i ai1 + ai2 +... + aiN ≤ ri.
All the numbers in input are non-negative and don't exceed 10\,000.
YES" (without quotes) if it's possible for the team 1 to score at least as much wins as any other team of its division, and "
NO" (without quotes) otherwise.
sample input |
sample output |
3 1 2 2 1 1 1 0 0 0 0 0 0 0 0 0 |
YES |
sample input |
sample output |
31 2 21 1 10 0 00 0 10 1 0 |
NO |
集训期间,实在太累,不写了。。。。。。待到开学再来慢慢写吧
#include <iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
using namespace std;
int n;
vector<int> v[1510];
int dp[1510] ,all[1510];
void solve(int x ,int pre)
{
int sum = 0;
dp[x] = 1;
all[x] = 0;
for(int i = 0;i < v[x].size();i++)
{
if(v[x][i]!=pre)
{
solve(v[x][i],x);
dp[x] += all[v[x][i]];
sum += dp[v[x][i]];
}
}
all[x] = min(dp[x],sum);
}
int main()
{
while(~scanf("%d",&n))
{
int index ,num ,no;
memset(dp,0,sizeof(dp));
memset(all,0,sizeof(all));
for(int i = 0;i<n;i++)
{
scanf("%d:(%d)",&index,&num);
for(int j = 0;j<num;j++)
{
scanf("%d",&no);
v[index].push_back(no);
v[no].push_back(index);
}
}
solve(0,-1);
printf("%d\n",all[0]);
for(int i = 0;i<n;i++)
{
v[i].clear();
}
}
return 0;
}