codeforces 690D2 D2. The Wall (medium)(组合数学)
题目链接:
2 seconds
256 megabytes
standard input
standard output
Heidi the Cow is aghast: cracks in the northern Wall? Zombies gathering outside, forming groups, preparing their assault? This must not happen! Quickly, she fetches her HC2 (Handbook of Crazy Constructions) and looks for the right chapter:
How to build a wall:
- Take a set of bricks.
- Select one of the possible wall designs. Computing the number of possible designs is left as an exercise to the reader.
- Place bricks on top of each other, according to the chosen design.
This seems easy enough. But Heidi is a Coding Cow, not a Constructing Cow. Her mind keeps coming back to point 2b. Despite the imminent danger of a zombie onslaught, she wonders just how many possible walls she could build with up to n bricks.
A wall is a set of wall segments as defined in the easy version. How many different walls can be constructed such that the wall consists of at least 1 and at most n bricks? Two walls are different if there exist a column c and a row r such that one wall has a brick in this spot, and the other does not.
Along with n, you will be given C, the width of the wall (as defined in the easy version). Return the number of different walls modulo106 + 3.
The first line contains two space-separated integers n and C, 1 ≤ n ≤ 500000, 1 ≤ C ≤ 200000.
Print the number of different walls that Heidi could build, modulo 10^6 + 3.
5 1
5
2 2
5
3 2
9
11 5
4367
37 63
230574 题意; 给n个砖,给定了宽c,问你有多少种墙;
这也是[1,n]的按顺序拆分成c个数的种数;也是把[1,n]放在c个盒子里(允许有空盒)的方案数; 思路: dp[n][m]=dp[n][m-1]+dp[n-1][m]+...+dp[0][m]+dp[n-1][m]+dp[n-2][m]+...+dp[1][m];
把n个相同的球放在m个盒子里(允许有空盒)的方案数为C(n+m-1,m-1);
dp[n][m]=C(n+m-1,m-1)=(n+m-1)/n*C(n+m-2,m-1)=(n+m-1)/n*dp[n-1][m];
取模的时候要快速幂求一下逆; AC代码:
#include <bits/stdc++.h>
/*
#include <vector>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <cstring>
#include <algorithm>
#include <cstdio>
*/
using namespace std;
#define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<''||CH>'';F= CH=='-',CH=getchar());
for(num=;CH>=''&&CH<='';num=num*+CH-'',CH=getchar());
F && (num=-num);
}
int stk[], tp;
template<class T> inline void print(T p) {
if(!p) { puts(""); return; }
while(p) stk[++ tp] = p%, p/=;
while(tp) putchar(stk[tp--] + '');
putchar('\n');
} const LL mod=1e6+;
const double PI=acos(-1.0);
const LL inf=1e18;
const int N=5e5+;
const int maxn=;
const double eps=1e-; LL n,m,dp[N]; LL pow_mod(LL x,LL y)
{
LL s=,base=x;
while(y)
{
if(y&)s=s*base%mod;
base=base*base%mod;
y>>=;
}
return s;
} void Init()
{
dp[]=;
for(LL i=;i<=n;i++)
{
dp[i]=(dp[i-]*(i+m-)%mod)*pow_mod(i,mod-)%mod;
}
} int main()
{
read(n);read(m);
Init();
LL sum=;
for(LL i=;i<=n;i++)
{
sum=(sum+dp[i])%mod;
}
cout<<sum<<"\n"; return ;
}
codeforces 690D2 D2. The Wall (medium)(组合数学)的更多相关文章
- The Wall (medium)
The Wall (medium) Heidi the Cow is aghast: cracks in the northern Wall? Zombies gathering outside, f ...
- Codeforces 1092 D2 Great Vova Wall (Version 2) (栈)
题意: 给一排砖,每列的高度$a_i$,问是否可以放1*2的砖,使得n列高度一样,砖只能横着放 思路: 每两个相邻的高度相同的砖可以变成大于等于它的高度的任意高度 所以像这样的 123321 是不满足 ...
- Codeforces - 1081C - Colorful Bricks - 简单dp - 组合数学
https://codeforces.com/problemset/problem/1081/C 这道题是不会的,我只会考虑 $k=0$ 和 $k=1$ 的情况. $k=0$ 就是全部同色, $k=1 ...
- Codeforces 1264D - Beautiful Bracket Sequence(组合数学)
Codeforces 题面传送门 & 洛谷题面传送门 首先对于这样的题目,我们应先考虑如何计算一个括号序列 \(s\) 的权值.一件非常显然的事情是,在深度最深的.是原括号序列的子序列的括号序 ...
- hdu-4810 Wall Painting(组合数学)
题目链接: Wall Painting Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- hdu 4810 Wall Painting (组合数学+二进制)
题目链接 下午比赛的时候没有想出来,其实就是int型的数分为30个位,然后按照位来排列枚举. 题意:求n个数里面,取i个数异或的所有组合的和,i取1~n 分析: 将n个数拆成30位2进制,由于每个二进 ...
- codeforces 677C C. Vanya and Label(组合数学+快速幂)
题目链接: C. Vanya and Label time limit per test 1 second memory limit per test 256 megabytes input stan ...
- codeforces D. Painting The Wall
http://codeforces.com/problemset/problem/399/D 题意:给出n和m,表示在一个n*n的平面上有n*n个方格,其中有m块已经涂色.现在随机选中一块进行涂色(如 ...
- Codeforces 932 E. Team Work(组合数学)
http://codeforces.com/contest/932/problem/E 题意: 可以看做 有n种小球,每种小球有无限个,先从中选出x种,再在这x种小球中任选k个小球的方案数 选出的 ...
随机推荐
- Scrapy学习-1-入门
基础知识 爬虫发展史 爬虫去重 1. 存储到数据库中 存取速度慢 2. 存储到内存中的集合里,内存占用十分大 当爬取数据有1亿条时 1*10**8*2Byte*50str_len/1024/102 ...
- shell的select脚本的简单入门
shell的select脚本的简单入门 语法:select var in ...;do break;doneecho $var 示例: #/bin/bash echo "what is yo ...
- OC-为何用copy修饰block
简单来说,block就像一个函数指针,指向我们要使用的函数. 就和函数调用一样的,不管你在哪里写了这个block,只要你把它放在了内存中(通过调用存在这个block的方 法或者是函数),不管放在栈中还 ...
- 洛谷—— P1605 迷宫
P1605 迷宫 题目背景 迷宫 [问题描述] 给定一个N*M方格的迷宫,迷宫里有T处障碍,障碍处不可通过.给定起点坐标和 终点坐标,问: 每个方格最多经过1次,有多少种从起点坐标到终点坐标的方案.在 ...
- centos6安装概述
1.1.选择安装类型:[Install or upgrade an existing system]安装或升级现有系统 1.2.介质校验:[Skip]跳过介质校验,校验时间较长 1.3.语言选择:[E ...
- 9.Java web—JSP内置对象
容器内置了9大对象,这些对象在jsp页无需实例化,可以直接使用. 分别为request. response .session. application .out. pageContext .confi ...
- 实现uitable cell中点击button设置当前cell为选中状态
- (void)buttonClick:(id)senser{ NSInteger tag = [senser tag]; NSLog(@"the button tag is % ...
- 谜题 之 C语言
本篇文章展示了14个C语言的迷题以及答案.代码应该是足够清楚的,并且我也相信有相当的一些样例可能是我们日常工作可能会见得到的.通过这些迷题,希望你能更了解C语言.假设你不看答案.不知道是否有把握回答各 ...
- weex 项目开发(二) weex 与 weexpack 的区别
1.weex 与 weexpack 即 weex-toolkit 与 weexpack 的区别 weex-toolkit 初始化的项目是针对开发单个 Weex 页面而设计的,也就是说这样的项目只包括 ...
- Android Studio——gradle同步出错:MALFORMED
Android Studio之前使用本地的gradle-2.10,而后创建新的工程总是报错,信息如下: Gradle sync failed: MALFORMED 而后在File->Projec ...