这题首先是找规律推公式,然后就是组合数学的知识了。

题目是问到第n行第m列的格式有几种方案,我们可以用手算的方法列出当n和m比较小时的所有答案

比如我列出以下8*8的矩阵


矩阵上的数表示从那个位置到最右下角一共有多少种方案。

求每个位置的值也简单,就是把它右下角的所有数加起来即可。

那么,把这个矩阵倒过来看,就是想要的结果矩阵了。

规律也很容易发现,首先,矩阵是对称的,所以我是只考虑m>=n的情况。

然后,可以发现每个位置的数就是一个组合数C(m + n - 4, n - 2)

最后就是求组合数取模了,C(m + n - 4, n - 2) %

然而,多年没做题的我,并不会组合数取模。找了以前的模板,是竹教主写的,看了好半天才明白,等我打完的时候,比赛刚结束。

比赛结束后交了一次,果然a了T_T

以下是代码

/*
* baidu/win.cpp
* Created on: 2016-5-22
* Author : ben
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <functional>
#include <numeric>
#include <cctype>
using namespace std;
typedef long long LL;
LL Ext_gcd(LL a, LL b, LL &x, LL &y) {
if (b == ) {
x = , y = ;
return a;
}
LL ret = Ext_gcd(b, a % b, y, x);
y -= a / b * x;
return ret;
}
LL Inv(LL a, int m) { ///求除数a对m的逆元;
LL d, x, y, t = (LL) m;
d = Ext_gcd(a, t, x, y);
if (d == )
return (x % t + t) % t;
return -;
}
void work(int n, int m) {
int i;
const int mod = ;
LL sum = ;
for (i = n - m + ; i <= n; i++) {
sum *= (LL) i;
sum %= mod;
}
LL tmp = ;
for (i = ; i <= m; i++)
tmp *= i, tmp %= mod; sum *= Inv(tmp, mod);
sum %= mod;
printf("%I64d\n", sum);
}
int main() {
int n, m;
while (scanf("%d%d", &n, &m) == ) {
if (m < n) {
int tmp = m;
m = n;
n = tmp;
}
work(m + n - , n - );
}
return ;
}

hdu5698 百度之星2016round2b第3题的更多相关文章

  1. 2018"百度之星"程序设计大赛 - 资格赛 - 题集

    1001 $ 1 \leq m \leq 10 $ 像是状压的复杂度. 于是我们(用二进制)枚举留下的问题集合 然后把这个集合和问卷们的答案集合 $ & $ 一下 就可以只留下被选中的问题的答 ...

  2. 2014年百度之星资格赛第三题Xor Sum

    Problem Description Zeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包括了N个正整数,随后 Prometheus 将向 Zeu ...

  3. 2014年百度之星资格赛第四题Labyrinth

    Problem Description 度度熊是一仅仅喜欢探险的熊.一次偶然落进了一个m*n矩阵的迷宫.该迷宫仅仅能从矩阵左上角第一个方格開始走.仅仅有走到右上角的第一个格子才算走出迷宫,每一次仅仅能 ...

  4. 2018 百度之星 初赛 第六题 HDU6349

    三原色图  Accepts: 281  Submissions: 1261  Time Limit: 1500/1000 MS (Java/Others)  Memory Limit: 262144/ ...

  5. 2019 年百度之星—初赛一 B题 Game

    题目链接 题意:最开始可以选择任意位置,在一个坐标轴上,依次走到一个区间里面,可以选择走一步两步,求最小步数. 思路:贪心,刚开始合并区间,确定初始位置以及方向.往右走肯定到左端点,往左走先到右端点, ...

  6. 百度之星B题(组合数)

    Problem B Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total ...

  7. 2016百度之星 初赛2A ABEF

    只做了1001 1002 1005 1006.剩下2题可能以后补? http://acm.hdu.edu.cn/search.php?field=problem&key=2016%22%B0% ...

  8. 2016百度之星 资格赛ABCDE

    看题:http://bestcoder.hdu.edu.cn/contests/contest_show.php?cid=690 交题:http://acm.hdu.edu.cn/search.php ...

  9. HDU 5688:2016"百度之星" - 资格赛 Problem D

    原文链接:https://www.dreamwings.cn/hdu5688/2650.html Problem D Time Limit: 2000/1000 MS (Java/Others)    ...

随机推荐

  1. sublime flatLand 主题

    今天试了下感觉主题不错 记下来备忘. 1.sublime3 package control install  搜索 flatLand 2 安装完成后. 修改 Preferences 文件,通过 Sub ...

  2. Change visual studio 2015 enterprise installation path(转)

    I would like to install VS2015 in a drive different than C:. The problem is that when I run the inst ...

  3. 一简单c++程序之反汇编

    #include<iostream> using namespace std; class point3d; class point2d; class point3d { private: ...

  4. unorder_set<typename T> 学习

    转自http://blog.csdn.net/mmzsyx/article/details/8240071 散列容器(hash container): 通常比二叉树的存储方式可以提供更高的访问效率.# ...

  5. kafka性能调优

    https://blog.csdn.net/u013063153/article/details/73826322

  6. AC日记——dispatching bzoj 2809

    2809: [Apio2012]dispatching Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 3290  Solved: 1740[Submi ...

  7. HDU 4587 TWO NODES 枚举+割点

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4587 TWO NODES Time Limit: 24000/12000 MS (Java/Other ...

  8. AtCoder - 2581 Meaningful Mean

    Problem Statement You are given an integer sequence of length N, a= {a1,a2,…,aN}, and an integer K. ...

  9. 2017 [六省联考] T6 寿司餐厅

    4873: [Shoi2017]寿司餐厅 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 450  Solved: 316[Submit][Status ...

  10. debian6之eclipse和jdk安装

    安装JDK 目前最新的JDK版本是:Java SE Development Kit 7u5 下载地址:http://www.oracle.com/technetwork/java/javase/dow ...