Sicily oj 1822. Fight Club(区间dp)

黑书上的原题,主要是你得想到拆点把一个点抽象成两个点。

题意: 一群人决斗, 给出一个人与另一个人决斗的胜负关系, 问结果合理决策每个人是否可以胜利.
解题思路:
1. 假设判断第i人是否可以胜出, 将第i人拆成2个人, 可以得出, 只要第i人能够与自己相遇
那么第i人就可以胜利.
2. 设dp[i][j]表示第i人是否可以与第j人相遇, vis[i][j]表示第i人与第j的决斗胜负关系.
(1). dp[i][j] = 能够相遇; 满足: dp[i][k]&&dp[j][k]&&(vis[i][k]||vis[j][k])
(2). dp[i][j] = 不能相遇;
3. 因为n个人围成一个圆, 我们可以扩大一倍人数, 方便计算i 等价 i+n;

PS:没看到最后要输出一个换行,还在那里找错误,sad啊、、、

1822. Fight Club

Constraints

Time Limit: 1 secs, Memory Limit: 32 MB

Description

Fight club is an organization where you release your pressure and emotion by fighting the other club members. The fight begins like this: n people standing in a circle. Then two adjacent guys are chosen to fight. The winner will stay and the loser will be sent to the hospital (there is no tie in the fighting). The cruel fight continues until there is only one left.
It is somewhat strange to see that when two guys fight each other, the result is always definite, and you know the result of every pair of fighters. Though they enjoy fighting, they still want to be the winner. You are to tell each of them, if the fight is arranged properly, can he be the winner.

Input

First line contains integer T (T<=5), the number of test cases.
For each test case, the first line contains n (1<=n<=40), the number of people. Following is the description of a n*n matrix A. Following n lines each contains n ‘0’ or ‘1’, separated by a single blank. The ith number in jth line indicates the fighting result of ith and jth fighter. If it is ‘1’, then the ith fighter will always beat the jth fighter, otherwise he will always lose. You can safely assume that aij and aji are different and aii=0 for every distinct i and j.
The people are numbered counterclockwise. 

Output

For each test case, output n lines. If the ith fighter can be the survivor, output 1, otherwise output 0.
Output a blank line after each test case. 

Sample Input

2
2
0 1
0 0
3
0 1 1
0 0 1
0 0 0

Sample Output

1
0

1
0
0
#include <algorithm>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
#define eps 1e-7
#define M 1000100
///#define LL __int64
#define LL long long
#define INF 0x3fffffff
#define PI 3.1415926535898

using namespace std;

const int maxn = 110;

int vis[maxn][maxn];
int dp[maxn][maxn];

int main()
{
    int T;
    cin >>T;
    while(T--)
    {
        int n;
        cin >>n;
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                cin >>vis[i][j];
        memset(dp, 0 ,sizeof(dp));
        for(int i = 0; i < 2*n; i++)
            dp[i][i+1] = 1;
        for(int len = 2; len <= n; len++)
        {
            for(int i = 0; i+len < 2*n; i++)
            {
                for(int j = i+1; j < i+len; j++)
                {
                    if(dp[i][j] && dp[j][i+len])
                    {
                        int x = (i+n)%n;
                        int y = (j+n)%n;
                        int z = (i+len+n)%n;
                        if(vis[x][y] || vis[z][y])
                            dp[i][len+i] = 1;
                    }
                }
            }
        }
        for(int i = 0; i < n; i++)
        {
            if(dp[i][i+n])
                cout<<1<<endl;
            else
                cout<<0<<endl;
        }
        cout<<endl;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值