【codechef】Lazy Players

Concerned with the fitness levels of the players in the National Team, the coach decides to carry out a running drill in the next training session. So, he sets up checkpoints in the training ground at different positions.

After evaluating each player’s fitness, the coach asks each player to cover a certain minimum distance while completing all checkpoints (Suppose a players starts at checkpoint 2, then he must cover all checkpoints and finish at checkpoint 2).

Players being lazy want to finish the drill in exact distance that the coach assigns them. Is it possible?

Input

Input description.

  • First line with two space separated integers N and L , the number of checkpoints and the minimum distance that coach asks the player to cover, respectively
  • Then N lines containing N space separated integers each. The jth integer on the ith line, dij, denotes the distance between checkpoint point i and j (dij for i != j, and dii = 0). For all 1 ≤ i, j, k ≤ N it is the case that dij = dji and dij ≤ dik + dkj.

Output

For each test case, output a single line containing the answer i.e. POSSIBLE or IMPOSSIBLE.

Constraints

  • 1 ≤ N ≤ 14
  • 1 ≤ L ≤ 1014
  • 1 ≤ dij ≤ L

Example

Input:

5 15
0 2 3 3 2
2 0 3 2 3
3 3 0 2 2
3 2 2 0 3
2 3 2 3 0

Output:

POSSIBLE

http://www.codechef.com/problems/LAZY01

Dij表示i到j的距离。经过每个点后的总距离能否刚好等于15

#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,l,sum;
    int a[14][14],i,j,k;
    cin>>n>>l;
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            cin>>a[i][j];
    for(i=0;i<n;i++){
        sum=0;
        for(j=0;j<n;j++){
            for(k=0;k<n;k++){
                if(sum<l){
                    sum+=a[i][k]+a[k][j];  //有点类似floyd,不过很巧妙的方法
                }
            }
        }
        if(sum==l){
            printf("POSSIBLE\n");
            break;
        }
    }
    if(i==n)
        printf("IMPOSSIBLE\n");
 
    return 0;
}
#include <stdio.h>
int main(void) {
	int a,b,i,j,max=0,sum=0;
	scanf("%d%d",&a,&b);
	int arr[a][a];
	for(i=0;i<a;i++)
	{
		for(j=0;j<a;j++)
		{
		scanf("%d",&arr[i][j]);
		}	
	}
	for(i=0;i<a;i++)
	{
		for(j=i+1;j<a;j++)
		{
			if(arr[i][j]>max)
			{
				max=arr[i][j];
			}
		}	
		sum+=max;
	}
	if(sum>=b)
	printf("POSSIBLE");
	else
	printf("IMPOSSIBLE");
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值