[NKU]sweet @ Google && TopCoder && CodeForces

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            33 Posts :: 1 Stories :: 15 Comments :: 0 Trackbacks
          數學苦手……一通推,無法可行……
          于是只能想沒有辦法的辦法:打表……

           1 #include <cstdio>
           2 #include <algorithm>
           3 
           4 using namespace std;
           5 typedef long long Long;
           6 
           7 int arr[20];
           8 Long ans = 0;
           9 int n;
          10 
          11 void dfs(int now,int sum) {
          12     if (sum < 0return;
          13     if (now == n) {ans ++return;}
          14     dfs (now + 1, sum + (1 << arr[now] ));
          15     dfs (now + 1, sum - (1 << arr[now] ));
          16 }
          17 
          18 int main() {
          19     for (n = 1; n <= 10; n++) {
          20         for (int i = 0; i < n; i++) {
          21             arr[i] = i;
          22         }
          23         Long cnt = 0;
          24         ans = 0;
          25         do {
          26              dfs(0,0);           
          27              cnt ++;
          28         } while (next_permutation(arr,arr + n));
          29         printf("%lld ",ans);
          30         printf("%lld\n",cnt << n);
          31     }
          32     return 0;
          33 }
          輸出:
          1 2
          3 8
          15 48
          105 384
          945 3840
          10395 46080
          135135 645120
          2027025 10321920
          34459425 185794560
          654729075 3715891200
          然后大家都懂了……
           1 import java.util.*;
           2 import java.io.*;
           3 import java.math.BigInteger;
           4 
           5 
           6 class Main {
           7 
           8     BigInteger[] ans1 = new BigInteger [501];
           9     BigInteger[] ans2 = new BigInteger [501];
          10     final BigInteger TWO = BigInteger.valueOf(2);
          11 
          12     void solve() throws Exception {
          13         MyReader in = new MyReader();
          14         int nn = in.nextInt();
          15         ans1[1= BigInteger.ONE;
          16         ans2[1= TWO;
          17         for (int i = 2; i <= 500; i++) {
          18             ans1[i] = ans1[i - 1].multiply(BigInteger.valueOf(i + i - 1));
          19             ans2[i] = ans2[i - 1].multiply(BigInteger.valueOf(i)).multiply(TWO);
          20             BigInteger gcd = ans1[i].gcd(ans2[i]);
          21             ans1[i] = ans1[i].divide(gcd);
          22             ans2[i] = ans2[i].divide(gcd);
          23         }
          24         PrintWriter out = new PrintWriter(System.out);
          25         while (nn-- > 0) {
          26             int n = in.nextInt();
          27             out.print(ans1[n]);
          28             out.print("/");
          29             out.println(ans2[n]);
          30         }
          31         out.flush();
          32     }
          33 
          34     public static void main(String args[]) throws Exception {
          35         new Main().solve();
          36     }
          37 
          38     void debug(Objectx) {
          39         System.out.println(Arrays.deepToString(x));
          40     }
          41 }
          42 
          43 class MyReader {
          44     BufferedReader br = new BufferedReader (
          45             new InputStreamReader (System.in));
          46     StringTokenizer in;
          47     String next() throws Exception {
          48         if (in == null || !in.hasMoreTokens()) {
          49             in = new StringTokenizer(br.readLine());
          50         }
          51         return in.nextToken();
          52     }
          53     int nextInt() throws Exception {
          54         return Integer.parseInt(next());
          55     }
          56 }
          posted on 2011-09-18 20:40 sweetsc 閱讀(797) 評論(1)  編輯  收藏

          Feedback

          # re: 2011ACM北京網絡預選賽D題: FXTZ II (BUPT 235) 2011-09-19 01:12 sxj_program
          It is not hard to understand that if the n-th power is shot then the game will be over.

          If it is shot at the i-th time, the possibility is (n-i)/n* f(i) * 1/(n-i)*1/2, which is 1/(2n)*f(i)

          So f(n) = 1/(2n)*sum( f(i) ), 1<=i<n

          f(n)*2n = sum( f(i) )
          => f(n)*2n - f(n-1)*2*(n-1) = f(n-1)
          => f(n) = (2n-1)/(2n)*f(n-1) = ... = (2n-1)!! / (2n)!! * f(0), f(0)=1  回復  更多評論
            


          只有注冊用戶登錄后才能發表評論。


          網站導航:
          博客園   IT新聞   Chat2DB   C++博客   博問  
           
          主站蜘蛛池模板: 临海市| 黎平县| 四子王旗| 新沂市| 浦江县| 井陉县| 永春县| 德保县| 巫溪县| 平果县| 嘉黎县| 和田市| 哈巴河县| 济阳县| 宁明县| 淄博市| 周宁县| 沁水县| 昌都县| 从化市| 鹰潭市| 桃园县| 河源市| 丹阳市| 思茅市| 武穴市| 阿鲁科尔沁旗| 汤原县| 卓尼县| 尤溪县| 塔城市| 大渡口区| 青铜峡市| 定南县| 岳阳市| 上思县| 湖北省| 靖西县| 黎平县| 建水县| 祥云县|