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

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 閱讀(907) 評論(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>
            欧美与黑人午夜性猛交久久久| 亚洲欧美综合国产精品一区| 男人的天堂亚洲| 久久黄色级2电影| 伊人天天综合| 美女国内精品自产拍在线播放| 久久精品一区二区| 在线播放日韩欧美| 亚洲电影免费在线观看| 久久尤物视频| 99国内精品| 亚洲自拍偷拍麻豆| 黄色国产精品一区二区三区| 欧美电影在线| 欧美午夜精品久久久久久人妖| 亚洲欧美一级二级三级| 欧美一区二区成人6969| 亚洲国产高清高潮精品美女| 亚洲二区三区四区| 国产精品捆绑调教| 久久免费国产精品| 亚洲欧美日韩在线一区| 欧美成年视频| 在线观看精品| 亚洲激情黄色| 国产精品久久久久国产精品日日 | 亚洲在线1234| 国产欧美日韩亚州综合| 久久裸体艺术| 欧美日韩一区二区三区| 久久久久久亚洲精品杨幂换脸| 免费欧美在线视频| 亚洲欧美日韩中文视频| 老妇喷水一区二区三区| 亚洲在线中文字幕| 久久一区二区三区国产精品| 亚洲综合欧美日韩| 免费日韩av电影| 久久国产视频网站| 欧美日韩国产在线| 女生裸体视频一区二区三区| 国产精品视频内| 亚洲国产综合在线看不卡| 国产午夜精品麻豆| 亚洲人成网站影音先锋播放| 曰本成人黄色| 亚洲欧美在线免费观看| 亚洲小少妇裸体bbw| 欧美成人国产| 久久综合伊人77777麻豆| 国产精品老牛| 一区二区欧美亚洲| 夜夜嗨av一区二区三区免费区| 久久久久这里只有精品| 久久精品女人| 国产精品一区二区三区乱码| 在线亚洲欧美| 亚洲网站在线| 欧美精品色一区二区三区| 免费成人小视频| 国产视频在线观看一区| 亚洲一级黄色片| 亚洲字幕一区二区| 国产精品超碰97尤物18| 99这里只有久久精品视频| 一本久道久久综合婷婷鲸鱼| 欧美成人精品三级在线观看| 欧美成人黑人xx视频免费观看| 尤物精品在线| 久久久综合视频| 免费成人黄色| 亚洲片区在线| 欧美精品免费在线| 亚洲茄子视频| 亚洲一级二级| 国产精品手机在线| 午夜精品久久久久久 | 国产一区二区剧情av在线| 一区二区三区四区五区精品| 亚洲午夜久久久久久久久电影院| 欧美日韩裸体免费视频| 一区二区三区欧美亚洲| 午夜精品久久久久久99热软件| 欧美色图天堂网| 中文一区字幕| 久久久久久婷| 亚洲黄色毛片| 欧美日韩在线播放一区| 亚洲一级网站| 免费毛片一区二区三区久久久| 亚洲激情在线视频| 欧美日韩在线视频一区| 亚洲欧美国产日韩天堂区| 久久久人成影片一区二区三区| 一区二区三区在线免费观看| 亚洲国产欧美另类丝袜| 日韩一级黄色片| 国产精品一区2区| 久久综合色88| 99精品久久免费看蜜臀剧情介绍| 翔田千里一区二区| 欧美日韩精品免费观看视一区二区| 一本色道**综合亚洲精品蜜桃冫 | 在线欧美日韩| 午夜欧美不卡精品aaaaa| 久久人人超碰| 一本到高清视频免费精品| 国产精品视频99| 久久躁日日躁aaaaxxxx| 99在线热播精品免费99热| 久久五月天婷婷| 在线亚洲一区观看| 国内久久精品| 国产精品久久久久久福利一牛影视| 久久精品国产在热久久| 亚洲视频一二三| 亚洲激情av在线| 久久亚洲精品一区二区| 亚洲永久精品大片| 91久久久久久| 黑人一区二区| 国产美女扒开尿口久久久| 欧美理论片在线观看| 久久综合福利| 久久国产加勒比精品无码| 宅男66日本亚洲欧美视频| 亚洲激情在线视频| 欧美成ee人免费视频| 久久男女视频| 久久精品国产99国产精品| 亚洲一区二区在线免费观看视频| 亚洲国产精品电影| 国产一区二区看久久| 国产日韩精品视频一区| 国产精品乱子久久久久| 欧美日韩成人综合天天影院| 欧美成人一区二区三区片免费| 久久久久久亚洲精品杨幂换脸| 亚洲欧美日韩中文视频| 亚洲在线观看| 亚洲小说欧美另类婷婷| 亚洲午夜av在线| 亚洲一区二区三区免费视频| aa成人免费视频| 99精品欧美一区二区三区综合在线| 91久久国产综合久久| 亚洲人成在线观看网站高清| 亚洲国产老妈| 亚洲精品影视| 夜夜嗨av一区二区三区| 在线视频你懂得一区二区三区| 日韩视频―中文字幕| 一本一本久久a久久精品牛牛影视| 亚洲精品在线免费| 99国产精品一区| 亚洲专区在线| 久久爱www久久做| 久久综合99re88久久爱| 欧美高清自拍一区| 欧美日韩国产黄| 国产精品r级在线| 国产欧美日本一区视频| 国内精品视频666| 亚洲第一精品电影| 日韩亚洲国产精品| 亚洲午夜一级| 久久久久久久一区| 欧美高清hd18日本| 日韩亚洲在线观看| 欧美一级大片在线观看| 久久伊人亚洲| 欧美日韩在线免费观看| 国产麻豆日韩| 亚洲国内在线| 亚洲伊人伊色伊影伊综合网| 欧美一区二区三区喷汁尤物| 免费久久99精品国产| 亚洲精品系列| 欧美一区午夜视频在线观看| 欧美v国产在线一区二区三区| 欧美日韩第一页| 国产专区欧美专区| 夜夜精品视频一区二区| 久久蜜桃精品| 99精品欧美| 免费毛片一区二区三区久久久| 欧美日韩国产系列| 国产视频一区免费看| 99国产精品| 久久一区免费| 一本色道久久综合狠狠躁篇怎么玩| 久久av在线看| 国产精品户外野外| 亚洲国产精品999| 久久大逼视频| 99精品国产在热久久婷婷| 久久亚洲欧美| 国产一区二区三区精品久久久| 99热免费精品在线观看| 麻豆91精品|