• <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>

            sgu 221

            Posted on 2010-12-07 20:33 王之昊 閱讀(312) 評論(0)  編輯 收藏 引用 所屬分類: sgu
            這是黑書上的一道例題(P243),在一個n*n的國際象棋棋盤上,放k只象,有多少種方法使得象之間不會攻擊。

            首先第一個觀察是白色格子和黑色格子是獨立的,可以分開考慮,注意二者不一定對稱。然后旋轉棋盤,得到一個菱形的期盼,注意到行列順序是無關的,所以可以交換行列,從小到大開始dp。

            附錄一:accept代碼(dp)
             1 //dp,黑書P243
             2 
             3 import java.util.Scanner;
             4 import java.util.*;
             5 import java.math.BigInteger;
             6 
             7 class biShop{
             8     int n, k;
             9     biShop(int _n, int _k){
            10         n = _n;
            11         k = _k;
            12     }
            13     
            14     BigInteger [] countOneSide(Vector<Integer> upper){
            15         int [] upp = new int[upper.size()];
            16         for(int i = 0; i < upp.length; i++){
            17             upp[i] = upper.get(i);
            18         }
            19         Arrays.sort(upp);
            20         
            21         BigInteger [] pre, now;
            22         now = new BigInteger[1]; 
            23         now[0= BigInteger.ONE;
            24         
            25         for(int i = 0; i < upp.length; i++){
            26             pre = now;
            27             now = new BigInteger[ upp[i] + 1 ];
            28             for(int j = 0; j < now.length; j++){
            29                 now[j] = BigInteger.ZERO;
            30                 if( j < pre.length )
            31                     now[j] = now[j].add( pre[j] );
            32                 if0 < j && j <= pre.length)
            33                     now[j] = now[j]. add( pre[j-1].multiply(BigInteger.valueOf(upp[i] - j + 1)) );
            34             }
            35         }
            36         return now;
            37     }
            38     
            39     BigInteger count(){
            40         Vector<Integer> A = new Vector<Integer>();
            41         Vector<Integer> B = new Vector<Integer>();
            42         
            43         A.add(n);
            44         for(int i = n-1, j = 0; i > 0; i--, j++){
            45             if( (j & 1== 0){
            46                 B.add(i);
            47                 B.add(i);
            48             }else{
            49                 A.add(i);
            50                 A.add(i);
            51             }
            52         }
            53         
            54         BigInteger [] a = countOneSide(A);
            55         BigInteger [] b = countOneSide(B);
            56         BigInteger res = BigInteger.ZERO;
            57         
            58         for(int i = 0; i <= k; i++){
            59             if(i >= a.length || k - i >= b.length)continue;
            60             res = res.add( a[i] .multiply( b[k-i]) );
            61         }
            62         return res;
            63     }
            64 }
            65 
            66 public class Solution{
            67     public static void main(String[] args)throws Exception{
            68         Scanner sc = new Scanner(System.in);
            69         
            70         biShop b = new biShop( sc.nextInt(), sc.nextInt() );
            71         
            72         System.out.println( b.count() );
            73     }    
            74 }



            posts - 26, comments - 7, trackbacks - 0, articles - 17

            Copyright © 王之昊

            久久亚洲精品中文字幕三区| 伊人久久大香线蕉AV一区二区| 精品久久久久中文字幕日本| 国产午夜免费高清久久影院| 国产精品禁18久久久夂久| 99精品国产在热久久无毒不卡 | 欧洲精品久久久av无码电影| 久久久久亚洲精品无码蜜桃| 久久精品成人免费网站| 热RE99久久精品国产66热| 一极黄色视频久久网站| 精品综合久久久久久88小说| 亚洲午夜无码AV毛片久久| 蜜臀av性久久久久蜜臀aⅴ麻豆| 久久久国产精华液| 久久国产亚洲精品无码| 四虎影视久久久免费| 久久亚洲精品国产精品| 久久国产精品免费一区二区三区| 2021最新久久久视精品爱| 国产亚洲精品美女久久久| 久久久久亚洲爆乳少妇无| 91精品国产色综合久久| 久久精品国产黑森林| 狠狠色丁香久久综合婷婷| 99久久精品国产一区二区| 久久精品成人免费观看97| 久久久久成人精品无码中文字幕| 久久亚洲天堂| 99久久国产免费福利| 久久久久99精品成人片欧美| 综合久久精品色| 国产精品美女久久久网AV| 91精品国产高清91久久久久久| 久久综合鬼色88久久精品综合自在自线噜噜 | 色青青草原桃花久久综合| 久久亚洲综合色一区二区三区| 亚洲AV日韩精品久久久久久 | 精品多毛少妇人妻AV免费久久 | 天天做夜夜做久久做狠狠| 久久99中文字幕久久|