[SDOI移动金币

链接

vijos

思路

阶梯博弈,dp统计.

参见wxyww

代码

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 7, mod = 1e9 + 9;
int read() {
int x = 0, f = 1; char s = getchar();
for (;s > '9' || s < '0'; s = getchar()) if (s == '-') f = -1;
for (;s >= '0' && s <= '9'; s = getchar()) x = x * 10 + s - '0';
return x * f;
}
int n, m, f[20][N], jc[N], inv[N];
int q_pow(int a, int b) {
int ans = 1;
while (b) {
if (b & 1) ans = 1LL * a * ans % mod;
a = 1LL * a * a % mod;
b >>= 1;
}
return ans;
}
int C(int n, int m) {return 1LL * jc[n] * inv[m] % mod * inv[n-m] % mod;}
int main() {
n = read(), m = read();
jc[0] = inv[0] = jc[1] = inv[1] = 1;
for (int i = 2; i <= n; ++i) {
jc[i] = 1LL * jc[i-1] * i % mod;
inv[i] = q_pow(jc[i], mod - 2);
}
int ans = C(n, m);
n -= m;
int num = (m + 1) >> 1;
f[0][0] = 1;
for (int i = 1; i <= 19; ++i) {
for (int j = 0; j <= n; ++j) {
for (int k = 0; (k << i - 1) <= j && k <= num; k += 2) {
f[i][j] += 1LL * f[i-1][j - (k << i - 1)] * C(num, k) % mod;
f[i][j] %= mod;
}
}
}
for (int i = 0; i <= n; ++i) {
ans -= 1LL * f[19][i] * C(n + m / 2 - i, m / 2) % mod;
ans = (ans + mod) % mod;
}
printf("%lld", ans);
return 0;
}

# [SDOI2019]移动金币 阶梯博弈 dp的更多相关文章

  1. P5363-[SDOI2019]移动金币【阶梯博弈,dp,组合数学】

    正题 题目链接:https://www.luogu.com.cn/problem/P5363 题目大意 \(1\times n\)的网格上有\(m\)个硬币,两个人轮流向前移动一个硬币但是不能超过前一 ...

  2. Luogu5363 SDOI2019移动金币(博弈+动态规划)

    容易想到可以转化为一个有m堆石子,石子总数不超过n-m的阶梯博弈.阶梯博弈的结论是相当于只考虑奇数层石子的nim游戏. nim和不为0不好算,于是用总方案数减掉nim和为0的方案数.然后考虑dp,按位 ...

  3. HDU 4315 Climbing the Hill (阶梯博弈转尼姆博弈)

    Climbing the Hill Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Su ...

  4. POJ1704 Georgia and Bob (阶梯博弈)

    Georgia and Bob Time Limit: 1000MS   Memory Limit: 10000KB   64bit IO Format: %I64d & %I64u Subm ...

  5. HDU 4315:Climbing the Hill(阶梯博弈)

    http://acm.hdu.edu.cn/showproblem.php?pid=4315 题意:有n个人要往坐标为0的地方移动,他们分别有一个位置a[i],其中最靠近0的第k个人是king,移动的 ...

  6. hdu 3389 Game (阶梯博弈)

    #include<stdio.h> int main() { int t,n,ans; int i,j,x; scanf("%d",&t); ;j<=t; ...

  7. HDU 5623 KK's Number (博弈DP)

    KK's Number 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/K Description Our lovely KK h ...

  8. poj 1704 阶梯博弈

    转自http://blog.sina.com.cn/s/blog_63e4cf2f0100tq4i.html 今天在POJ做了一道博弈题..进而了解到了阶梯博弈...下面阐述一下我对于阶梯博弈的理解. ...

  9. [BZOJ 1115] [POI2009] 石子游戏Kam 【阶梯博弈】

    题目链接:BZOJ - 1115 题目分析 首先看一下阶梯博弈: 阶梯博弈是指:初始有 n 堆石子,每次可以从任意的第 i 堆拿若干石子放到第 i - 1 堆.最终不能操作的人失败. 解法:将奇数位的 ...

随机推荐

  1. Linux学习笔记之Linux磁盘及文件系统管理笔记

    Linux磁盘及文件系统管理 CPU,memory(RAM),I/O i/o: disks,ehtercard disks:持久存储数据 接口类型: IDE(ata): 并口,133MB/s;并行总线 ...

  2. javascript query string

    function getQueryVariable(variable) { var query = window.location.search.substring(1); var vars = qu ...

  3. 【3.1】学习C++之再逢const

    随着学习的深入,就会发现曾经学的const还有更深入的用法,现在就对const的未总结的用法进行总结. 本文就是针对const在类中的情况进行的总结. 有时我们会遇到下面这种将类的成员变量用const ...

  4. Elasticsearch DSL 常用语法介绍

    课程环境 CentOS 7.3 x64 JDK 版本:1.8(最低要求),主推:JDK 1.8.0_121 Elasticsearch 版本:5.2.0 相关软件包百度云下载地址(密码:0yzd):h ...

  5. java log4j 打日志到控制台同时打印到不同文件

    1.pom配置 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="htt ...

  6. Spring Boot 复习

    简介 Spring Boot 是由 Pivotal 团队提供的全新框架,其设计目的是用来简化新 Spring 应用的初始搭 建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义 ...

  7. iOS - 适配 iOS 13 之工兵连扫雷

    iOS 13 支持适配的机型 目前最新 iPhone 11.iPhone 11 Pro和iPhone 11 Pro Max iPhone X.iPhone XR.iPhone XS.iPhone XS ...

  8. css, js 项目练习之网页换肤

    首先,该练习参考自:https://www.jianshu.com/p/2961d9c317a3 我就直接上代码了(颜色可以自己调). HTML: <nav> <li>< ...

  9. 91.用js遍历原生json数据

    <!doctype html> <html lang="en"> <head>     <meta charset="UTF-8 ...

  10. react的事件处理为什么要bind this 改变this的指向?

    react的事件处理会丢失this,所以需要绑定,为什么会丢失this? 首先来看摘自官方的一句话: You have to be careful about the meaning of this ...