uva11758 Problem Solving report (one of God's games)

Source: Internet
Author: User
Tags printf

Topic Link https://uva.onlinejudge.org/index.php?option=com_onlinejudge&itemid=8&page=show_problem& problem=2858

Test instructions: Give you a one-dimensional chessboard, the size of N, and then give you k pieces, K must be even, there are k/2 gray pieces, k/2 white pieces, gray and white must be placed in pairs (first gray after white) and then two people, A, B, each can be an operation, you can choose which D pieces (a can only select gray, B can only choose white) let this pawn move left or right to move any step (at least one piece to choose to move one step) ask you how many kinds of placement, so that the initiator win

 parsing: Analysis, gray pieces to the left is meaningless, (with the same propulsion operation, the situation is unchanged) Similarly, white pieces to the right also meaningless. So we only consider Gray to the right and white to the left.
So it seems that every pair of pieces is a NIM game.
However, because the initiator can choose the D heap to operate, to win the state must be a high degree of complexity, then the contrary, the total pendulum minus the hand to win is the initiator win.
For such a K-Heap Nim, each time the selection of 1-d heap operation, there is a theorem, that is, the a1,a2,a3...ak of each binary and must be (d+1) a multiple (can be 0) This is the condition of the win.
As for why, simply put it, not strictly proven. Suppose A1,a2,a3...ak's bits is written (each number is a column, from the lowest bit to the 18th bit (generally 18, not enough)) for each row to meet the number of 1 is a multiple of d+1, we call this state as the equilibrium state. The initiator encounters this equilibrium state must defeat. If the initiator randomly destroy this equilibrium state, for the next, because can also choose up to D number, and then the initiator each took off some of the bits on the 1 take off can (this is more abstract, can be understood, is 10 sweets, up to a minimum of D to take one, of course, winning strategy is your opponent took a A, you take d+1- A not on the line (the balance of the winning strategy) after the conclusion, assuming that A1,A2,..., AK has been determined, then not sure is his position, and a1,a2...ak how big no half-dime relationship. And then this problem becomes a DP count question (similar to digital DP) DP[I][J] means the forward, the right and the number of J is a bit of a backpack just like that. Enumerate the number of this line 1 m satisfies d+1|m, make a selection on the line, and finally calculate how many kinds of a1-ak (packing each heap into, permutation) algorithm is Jiangzi 
Created by matrix on 2015-11-26//Copyright (c) to matrix.
All rights reserved. //#pragma COMMENT (linker, "/stack:102400000,102400000") #include <algorithm> #include <cctype> # Include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iomanip > #include <iostream> #include <map> #include <queue> #include <string> #include <sstream&
Gt #include <set> #include <vector> #include <stack> #define ALL (x) X.begin (), X.end () #define INS (x) inser
ter (x, X,begin ()) #define LL Long long #define CLR (x) memset (x, 0, sizeof x) using namespace std;
const int inf = 0X3F3F3F3F;
CONST LL MOD = 1e9 + 7;
const int MAXN = 1e2 + 10;
const int MAXV = 1E3 + 10;

Const double EPS = 1e-9;
int t;
int N, K, D;
LL C[MAXN * 100][MAXN];
LL DP[20][MAXV * 10]; int main () {#ifdef LOCAL freopen ("In.txt", "R", stdin),//Freopen ("OUT.txt", "w", stdout), #endif scanf ("%d", &am
    P;T); for (iNT i = 1; I <= 10000;
        i++) {c[i][0] = c[i][i] = 1;
        for (int j = 1; J < min (103, I); j + +) {C[i][j] = (C[i-1][j] + c[i-1][j-1])% MOD;
        }} while (t--) {scanf ("%d%d%d", &n, &k, &d);
        K/= 2;
        CLR (DP);
        Dp[0][0] = 1; 
                for (int i = 0, I < i++) {for (int j = 0; J * (1 << i) <= n && J <= k; j + = d + 1) {
                int num = J * (1 << i); 
                for (int w = n-2 * k; w >= num; w--) {dp[i+1][w] = (Dp[i+1][w] + dp[i][w-num] * c[k][j])% MOD;
}}} ll ans = c[n][2*k];
        printf ("ans =%lld\n", ans);
            for (int i = 0; I <= n-2 * k; i++) {//printf ("dp[%d] =%lld\n", I, dp[15][i]);
ll res = c[n-i-k][k] * Dp[15][i]% MOD;
            printf ("res[%d] =%lld\n", I, RES);
        Ans = (ans-res + mod)% MoD; } cout << ans << Endl;
} return 0; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.