Codeforces 233 D - Table
思路:dp
首先,第i列的个数肯定和第i - n列个数一样,假设[i - n + 1, i - 1] 之间的个数之和为x,那么第i列和第i-n列的个数应该是n - x
那么我们可以用dp求方案数
状态:dp[i][j] 表是到第 i 列为止 填了 j 个的方案数
初始状态: dp[0][0] = 1
状态转移: dp[i][j](1 <= i <= n, 0 <= j <= k) = ∑(dp[i-1][j - l](l <= n && j >= l) * C(n, l) ^ cnt)
其中,cnt = n/m 或者 n/m + 1,C(n, l)^cnt 可以预处理来降低复杂度
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int MOD = 1e9 + ;
const int N = ;
LL dp[N][N*N];
LL qp[N][N][];
LL q_pow(LL n, LL k) {
LL ans = ;
while(k) {
if(k&) ans = (ans * n) % MOD;
n = (n * n) % MOD;
k >>= ;
}
return ans;
}
int main() {
int n, k;
LL m;
scanf("%d %lld %d", &n, &m, &k);
LL cnt = m/n;
LL C = ;
for (int i = ; i <= n; i++) {
qp[n][i][] = q_pow(C, cnt);
qp[n][i][] = q_pow(C, cnt+);
C = (C * (n-i)) % MOD;
C = (C * q_pow(i+, MOD-)) % MOD;
}
dp[][] = ;
for (int i = ; i <= n; i++) {
for (int j = ; j <= k; j++) {
for (int l = ; l <= n && j >= l; l++) {
if(i <= m%n) dp[i][j] = (dp[i][j] + dp[i-][j-l] * qp[n][l][]) % MOD;
else dp[i][j] = (dp[i][j] + dp[i-][j-l] * qp[n][l][]) % MOD;
}
}
}
printf("%lld\n", dp[n][k]);
return ;
}
Codeforces 233 D - Table的更多相关文章
- codeforces 233 D. Table(思维+dp )
题目链接:http://codeforces.com/contest/233/problem/D 题意:问在n*m的矩阵中满足在每一个n*n的矩阵里画k个点,一共有几种画法. 题解:其实这题挺简单的但 ...
- Codeforces 417E Square Table(随机算法)
题目链接:Codeforces 417E Square Table 题目大意:给出n和m.要求给出一个矩阵,要求每一列每一行的元素的平方总和是一个平方数. 解题思路:构造.依照 a a a b a a ...
- CodeForces 1099E - Nice table - [好题]
题目链接:https://codeforces.com/problemset/problem/1099/E You are given an $n×m$ table, consisting of ch ...
- codeforces 233 C. Cycles(贪心+思维)
题目链接:http://codeforces.com/contest/233/problem/C 题意:在一个无相图中有N个长度为3 的回路,输出符合条件的图.注意此图的节点数不得超过100 题解:贪 ...
- codeforces 582A. GCD Table 解题报告
题目链接:http://codeforces.com/problemset/problem/582/A 网上很多题解,就不说了,直接贴代码= = 官方题解: http://codeforces.com ...
- codeforces D. Multiplication Table
http://codeforces.com/contest/448/problem/D 题意:一个n×m的矩阵,a[i][j]=i*j; 然后把a数组排序,找出第k个数. 思路:1-n×m二分枚举,然 ...
- Codeforces 22B Bargaining Table
http://www.codeforces.com/problemset/problem/22/B 题意:求出n*m的方格图中全是0的矩阵的最大周长 思路:枚举 #include<cstdio& ...
- Codeforces #662C Binary Table
听说这是一道$ Tourist$现场没出的题 Codeforces #662C 题意: 给定$n*m的 01$矩阵,可以任意反转一行/列($0$变$1$,$1$变$0$),求最少$ 1$的数量 $ n ...
- Codeforces 40E Number Table - 组合数学
题目传送门 传送门I 传送门II 题目大意 给定一个$n\times m$的网格,每个格子上要么填$1$,要么填$-1$,有$k$个位置上的数是已经填好的,其他位置都是空的.问有多少种填法使得任意一行 ...
随机推荐
- 【Selenium专题】元素定位之CssSelector
CssSelector是我最喜欢的元素定位方法,Selenium官网的Document里极力推荐使用CSS locator,而不是XPath来定位元素,原因是CSS locator比XPath loc ...
- Python3 join函数和os.path.join用法
Python3 join函数和os.path.join用法 os.path.join()连接两个文件名地址的时候,就比os.path.join("D:\","test. ...
- php5.3.x连接MS SQL server2008
开篇 因为毕设老师需求的原因,虚拟旅游网站要求的数据库必须使用MS SQL server. 我最擅长的web编程语言是PHP,但是在PHP中链接MS SQL server是一件非常麻烦的事,我个人分析 ...
- 细数php里的那些“坑”
Part 1 Grammer 尽管PHP的语法已经很松散,写起来很“爽”.但是对于学过 Java 的“完全面向对象程序员“来说,PHP程序设计语言里,还是有一些的坑的.下面请让我来盘点一下. Pars ...
- win7 powershell配色方案
首先我是参考微软的word的, look~ Windows PowerShell 配置文件 要配置powershell很简单, 就几步 1.显示 Windows PowerShell 配置文件的路径 ...
- (12网络化部署深化下)自己动手,编写神经网络程序,解决Mnist问题,并网络化部署
网络化部署一直是我非常想做的,现在已经基本看到了门路.今天早上实验,发现在手机上的支持也非常好(对于相机的支持还差一点),证明B/S结构的框架是非常有生命力的.下一步就是要将这个过程深化.总结,并且封 ...
- CS224n学习笔记(一)
How do we have usable meaning in a computer? Represents the words as discrete symbols, (离散型变量) Use t ...
- USB通信基础知识
1 USB系统组成 主机:提供USB接口和接口管理功能的硬件.软件.固件的复合体.PC机或OTG设备,一个USB系统只能有一个主机 设备:1.集线器HUB:扩展主机接口,设备可以通过其接入主机 2. ...
- Error: php71w-common conflicts with php-common-5.4.16-46.el7.x86_64
Centos7.3 阿里云主机 安装zabbix报错 问题: [root@lvhanzhi code]# yum install -y zabbix-web-mysql zabbix-agent ma ...
- MongoDB NoSQL 常用指令
查询 日期区间 db.<collections>.find({"service_name":"xxx"}).sort({ update_time:- ...