青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

coreBugZJ

此 blog 已棄。

POJ 2068 Nim

  1/*
  2POJ 2068 Nim
  3
  4
  5----問題描述:
  6
  7Let's play a traditional game Nim. You and I are seated across a table and we have a hundred stones on the table (we know the number of stones exactly). We play in turn and at each turn, you or I can remove on to four stones from the heap. You play first and the one who removed the last stone loses. 
  8
  9In this game, you have a winning strategy. To see this, you first remove four stones and leave 96 stones. No matter how I play, I will end up with leaving 92 - 95 stones. Then you will in turn leave 91 stones for me (verify this is always possible). This way, you can always leave 5k+1 stones for me and finally I get the last stone, sigh. If we initially had 101 stones, on the other hand, I have a winning strategy and you are doomed to lose. 
 10
 11Let's generalize the game a little bit. First, let's make it a team game. Each team has n players and the 2n players are seated around the table, with each player having opponents at both sides. Turn around the table so the two teams play alternately. Second, let's vary the maximum number of stones each player can take. That is, each player has his/her own maximum number of stones he/she can take at each turn (The minimum is always one). So the game is asymmetric and may even be unfair. 
 12
 13In general, when played between two teams of experts, the outcome of a game is completely determined by the initial number of stones and the maximum number of stones each player can take at each turn. In other words, either team has a winning strategy. 
 14
 15You are the head-coach of a team. In each game, the umpire shows both teams the initial number of stones and the maximum number of stones each player can take at each turn. Your team plays first. Your job is, given those numbers, to instantaneously judge whether your team has a winning strategy. 
 16
 17Incidentally, there is a rumor that Captain Future and her officers of Hakodate-maru love this game, and they are killing their time playing it during their missions. You wonder where the stones are? Well, they do not have stones but do have plenty of balls in the fuel containers!
 18
 19
 20----輸入:
 21
 22The input is a sequence of lines, followed by the last line containing a zero. Each line except the last is a sequence of integers and has the following format. 
 23
 24n S M1 M2 . . . M2n 
 25
 26where n is the number of players in a team, S the initial number of stones, and Mi the maximum number of stones ith player can take. 1st, 3rd, 5th,  players are your team's players and 2nd, 4th, 6th,  the opponents. Numbers are separated by a single space character. You may assume 1 <= n <= 10, 1 <= Mi <= 16, and 1 <= S < 2^13.
 27
 28
 29----輸出:
 30
 31The output should consist of lines each containing either a one, meaning your team has a winning strategy, or a zero otherwise.
 32
 33
 34----樣例輸入:
 35
 361 101 4 4
 371 100 4 4
 383 97 8 7 6 5 4 3
 390
 40
 41
 42----樣例輸出:
 43
 440
 451
 461
 47
 48
 49----分析:
 50
 51博弈DP ,記憶化搜索。
 52
 53
 54*/

 55
 56
 57#include <iostream>
 58#include <cstdio>
 59#include <cstring>
 60
 61using namespace std;
 62
 63const int N = 29;
 64
 65int n, s, m[ N ], f[ N ][ (1<<13+ 9 ];
 66
 67        // 到第 i 個人,面對 j 個石子,奇數方勝則為 1,敗則為 0 .
 68int dp( int i, int j ) {
 69        if ( -1 != f[ i ][ j ] ) {
 70                return f[ i ][ j ];
 71        }

 72
 73        if ( 0 == j ) {
 74                return ( f[ i ][ j ] = (i & 1) );
 75        }

 76
 77        int k;
 78        f[ i ][ j ] = 1 - (i & 1);
 79        for ( k = 1; (k <= j)&&(k <= m[ i ]); ++k ) {
 80                if ( (i & 1== dp( i%n+1, j - k ) ) {
 81                        f[ i ][ j ] = (i & 1);
 82                        break;
 83                }

 84        }

 85        return f[ i ][ j ];
 86}

 87
 88int main() {
 89        int i;
 90        while ( (1 == scanf( "%d"&n )) && (0 < n) ) {
 91                scanf( "%d"&s );
 92                n <<= 1;
 93                for ( i = 1; i <= n; ++i ) {
 94                        scanf( "%d", m+i );
 95                }

 96                memset( f, 0xFFsizeof(f) );
 97                printf( "%d\n", dp( 1, s ) );
 98        }

 99        return 0;
100}

101

posted on 2012-06-04 16:03 coreBugZJ 閱讀(897) 評論(0)  編輯 收藏 引用 所屬分類: ACMAlgorithmMathematics課內作業

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲精品一二三区| 香蕉久久精品日日躁夜夜躁| 欧美日韩国产经典色站一区二区三区| 久久久精品日韩欧美| 久久国产精品久久久久久久久久| 久久精品国产96久久久香蕉 | 正在播放亚洲一区| 中国成人亚色综合网站| 亚洲欧美一区二区三区极速播放| 午夜精品久久久久久久蜜桃app | 亚洲精品综合精品自拍| 一区二区三区波多野结衣在线观看| 亚洲亚洲精品在线观看| 久久精品中文字幕一区| 欧美大片免费| 亚洲视频一区二区免费在线观看| 久久精品国产99| 欧美三级视频在线观看| 国产在线一区二区三区四区 | 裸体女人亚洲精品一区| 日韩一区二区电影网| 久久成人免费视频| 亚洲视频香蕉人妖| 国产在线国偷精品产拍免费yy| 美女精品视频一区| 亚洲另类在线视频| 久久精品夜色噜噜亚洲aⅴ| 亚洲国产另类精品专区| 亚洲一区二区少妇| 欧美日韩成人免费| 亚洲电影免费观看高清完整版| 亚洲免费小视频| 亚洲日本中文字幕免费在线不卡| 久久精品国产一区二区三| 国产精品看片你懂得| 一本色道久久88综合日韩精品| 久久综合伊人77777尤物| 亚洲欧美日韩系列| 国产精品嫩草影院av蜜臀| 99精品国产在热久久婷婷| 欧美成人激情在线| 亚洲午夜高清视频| 欧美日韩综合网| 亚洲乱码国产乱码精品精98午夜| 久久久国产亚洲精品| 亚洲永久精品国产| 国产精品国产三级国产aⅴ浪潮| 亚洲精品自在久久| 欧美成人精品在线观看| 亚洲精品一品区二品区三品区| 免费在线亚洲| 国内精品美女av在线播放| 久久精品视频免费| 久久aⅴ国产紧身牛仔裤| 国内精品久久久久久久影视蜜臀| 久久精品国产2020观看福利| 亚洲男人av电影| 国产精品一区二区你懂得| 香蕉久久夜色精品国产使用方法| 宅男精品视频| 国产女人精品视频| 久久久成人网| 久久综合九色99| 亚洲欧洲日本在线| 亚洲精品综合精品自拍| 欧美视频二区36p| 午夜精品久久久久久| 午夜亚洲视频| 亚洲大胆女人| 亚洲人人精品| 国产精品v亚洲精品v日韩精品 | 一区二区三区欧美激情| 亚洲七七久久综合桃花剧情介绍| 欧美精品一区二区视频| 国产精品99久久久久久久久 | 你懂的一区二区| 亚洲国产精品久久久久秋霞不卡| 美脚丝袜一区二区三区在线观看 | 亚洲国产高清aⅴ视频| 欧美猛交免费看| 性做久久久久久久免费看| 99热这里只有精品8| 国产精品嫩草影院av蜜臀| 久久久91精品国产| 免费观看国产成人| 亚洲综合日本| 久久国产精品毛片| 亚洲精品美女久久7777777| 99精品免费| 国产欧美日韩一区二区三区| 国产精品免费网站在线观看| 久久激情视频久久| 久久久久久高潮国产精品视| 亚洲国产成人在线播放| 99精品视频免费观看视频| 国产精品成人免费视频| 久久爱www| 欧美日韩国产美| 久久久欧美一区二区| 欧美女同视频| 免费成人黄色av| 国产精品久久久久aaaa| 美女国产精品| 国产午夜久久久久| 一本综合久久| 亚洲人午夜精品| 性欧美大战久久久久久久免费观看| 136国产福利精品导航网址| 亚洲一区二区成人在线观看| 在线观看欧美黄色| 亚洲中字在线| 亚洲视频欧美视频| 久久综合影视| 国内精品视频666| 亚洲丰满在线| 亚洲在线观看视频网站| 香蕉久久国产| 国产精品亚洲综合一区在线观看| 久久精品一区四区| 欧美高清一区二区| 亚洲电影网站| 亚洲国产精品久久久久久女王| 欧美一区免费| 久久gogo国模裸体人体| 国产精品h在线观看| 亚洲黄色一区| 亚洲精品一区二区三区樱花 | 国产精品久久一级| 99re热精品| 一区二区三区精品视频| 欧美插天视频在线播放| 欧美成人乱码一区二区三区| 免费永久网站黄欧美| 亚洲国产小视频在线观看| 国产精品久久久久永久免费观看| 亚洲欧美日韩在线播放| 欧美激情久久久| 久久九九免费视频| 最新中文字幕亚洲| 亚洲精品免费网站| 亚洲欧洲精品一区二区三区不卡| 久久久亚洲高清| 免费在线观看成人av| 亚洲激情一区二区三区| 久久久久久9| 亚洲成色www久久网站| 亚洲精品乱码久久久久久按摩观| 久久久国产成人精品| 久久一区二区三区av| 樱桃国产成人精品视频| 久久精品中文字幕一区| 欧美插天视频在线播放| 一本色道久久综合亚洲精品不卡| 久久漫画官网| 看片网站欧美日韩| 亚洲综合色噜噜狠狠| 亚洲国产精品欧美一二99| 国产精品婷婷午夜在线观看| 亚洲综合丁香| 国产日韩欧美另类| 久久久91精品国产| 亚洲欧洲另类| 欧美一区二区三区久久精品| 国产精品一级二级三级| 久久精品国产亚洲5555| 亚洲国产91色在线| 日韩一区二区精品在线观看| 国产精品日韩电影| 久久精品国产免费看久久精品| 久久影音先锋| 日韩视频中文| 好吊妞**欧美| 欧美日韩一区在线| 久久久久综合网| 亚洲一区二区精品| 亚洲国产精品精华液2区45| 国产精品草草| 国产精品久久久久久久第一福利 | 亚洲福利视频一区| 欧美三级日韩三级国产三级| 久久久久久日产精品| 在线视频你懂得一区| 欧美黄在线观看| 久久婷婷国产麻豆91天堂| 一区二区三区四区五区视频| 一区在线视频观看| 国产精品久久久久一区二区| 麻豆av一区二区三区| 久久成人av少妇免费| 在线中文字幕一区| 亚洲电影免费观看高清完整版在线| 欧美在线1区| 亚洲午夜未删减在线观看| 女生裸体视频一区二区三区| 亚洲图片欧美一区| 午夜精品视频在线观看一区二区 | 国产人成一区二区三区影院| 欧美日韩高清在线一区| 久久久精品一区| 亚洲网站视频福利|