| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1441 人关注过本帖
标题:有环图的DP怎么用,怎么定义状态
取消只看楼主 加入收藏
a1004573547
Rank: 2
等 级:论坛游民
帖 子:78
专家分:25
注 册:2013-3-11
结帖率:40%
收藏
已结贴  问题点数:10 回复次数:7 
有环图的DP怎么用,怎么定义状态
10306 Prison break

时间限制:1000MS  内存限制:65535K
提交次数:17 通过次数:4

题型: 编程题   语言: 无限制
Description

Mike was going to escape from the prison when he knew how to do it. However, many other people realized his secret and asked him for help. But,
to avoid being caught by guards, Mike could only take one people with him. By thinking for a minute, an idea came out in his mind to choose one
from all the people who wanted to break the prison:
Let all the n people (assuming they are numbered from 0 to n-1) gather together in a circle and play a game, the one who wins in the end might
have a chance to escape with Mike.
Here is the rule of the game:
Select two people adjacent to each other in the circle randomly, and then they might fight between each other. The loser in the fight has to quit
the game and the winner can stay. Repeat this step until there is only one person left and this person can go with Mike.  
As Mike was a clever man (even though not so careful for letting others know his plan), he knew exactly who will win between i and j before the
two people fight each other, and he draw a n*n matrix G in which G(i,j)=1 means i can win j during the game, while G(i,j)=0 in opposite. And now,
Mike would like to know the list of the people who cannot escape with him no matter in which order the fights are arranged, can you help him?




输入格式

The first line of the input is an integer T indicating the number of the case, and in each case, the first line of the case is an integer n
indicating the number of people. Then a n*n matrix G follows whose meaning has been shown above. (1 <= n <= 100)



输出格式

You should output the numbers of the people who might not have a chance to escape in any situations. These numbers should be printed out in
ascending order and there is only one number in each line. If everyone might have a chance to escape, print out “none” instead.



输入样例

2
4
0 0 0 0
1 0 0 0
1 1 0 0
1 1 1 0
4
0 0 0 1
1 0 1 0
1 0 0 1
0 1 0 0



输出样例

0
1
2
none



提示

4
0 0 0 1
1 0 1 0
1 0 0 1
0 1 0 0
Let us see this sample:
Since 0 can beat 3, 3 beats 1 and 1 beats 2, so 0 can win the game to escape. It is also easy to find that prisoner 1, 2, 3 might have the chance to win the game. So the output is “none”.


搜索更多相关主题的帖子: all his secret people escape 
2013-04-03 15:48
a1004573547
Rank: 2
等 级:论坛游民
帖 子:78
专家分:25
注 册:2013-3-11
收藏
得分:0 
懂的说两句也行  不要求代码
2013-04-03 15:50
a1004573547
Rank: 2
等 级:论坛游民
帖 子:78
专家分:25
注 册:2013-3-11
收藏
得分:0 
回复 3楼 czz5242199
什么意思
2013-04-03 18:41
a1004573547
Rank: 2
等 级:论坛游民
帖 子:78
专家分:25
注 册:2013-3-11
收藏
得分:0 
#include<stdio.h>
#include<string.h>
int meet[220][220],fight[120][120];


main(){
    int T,n,i,j,k,flag;
    scanf("%d",&T);
    while(T--){
        memset(meet,0,sizeof(meet));
        scanf("%d",&n);
        for(i=0;i<n;i++)
        for(j=0;j<n;j++)
        scanf("%d",&fight[i][j]);
        for(i=0;i<n;i++){
            meet[i][i+1]=meet[i+1][i]=meet[i+n][i+n+1]=meet[i+n+1][i+n]=1;
        }
        for(k=2;k<=n;k++){
            for(i=0;i<n;i++)
            for(j=i+1;j<i+k;j++){
                if(!meet[i][i+k]&&meet[i][j]&&meet[j][i+k]&&(fight[i][j%n]||fight[(i+k)%n][j%n])){
                    meet[i][i+k]=meet[i+k][i]=1;
                    if(i+n<220&&i+k+n<220) meet[i+n][i+k+n]=meet[i+k+n][i+n]=1;
                    break;
                }
            }
        }
        for(i=flag=0;i<n;i++){
            if(!meet[i][i+n]) {
                printf("%d\n",i);
                flag=1;
            }
        }
        if(!flag) printf("none\n");
    }
}


代码在这里  求解释
2013-04-03 18:52
a1004573547
Rank: 2
等 级:论坛游民
帖 子:78
专家分:25
注 册:2013-3-11
收藏
得分:0 
回复 6楼 beyondyf
谢谢。   OJ是我们学校的,不对外开放。   其他OJ也有类似的题目 剑客对决
2013-04-04 19:28
a1004573547
Rank: 2
等 级:论坛游民
帖 子:78
专家分:25
注 册:2013-3-11
收藏
得分:0 
回复 6楼 beyondyf
BFT是什么
2013-04-04 19:32
a1004573547
Rank: 2
等 级:论坛游民
帖 子:78
专家分:25
注 册:2013-3-11
收藏
得分:0 
回复 6楼 beyondyf
解释下那个状态方程。。。。不能理解
2013-04-04 19:45
a1004573547
Rank: 2
等 级:论坛游民
帖 子:78
专家分:25
注 册:2013-3-11
收藏
得分:0 
回复 10楼 beyondyf
嗯嗯,谢了!
2013-04-05 20:26
快速回复:有环图的DP怎么用,怎么定义状态
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.051452 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved