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的更多相关文章

  1. codeforces 233 D. Table(思维+dp )

    题目链接:http://codeforces.com/contest/233/problem/D 题意:问在n*m的矩阵中满足在每一个n*n的矩阵里画k个点,一共有几种画法. 题解:其实这题挺简单的但 ...

  2. Codeforces 417E Square Table(随机算法)

    题目链接:Codeforces 417E Square Table 题目大意:给出n和m.要求给出一个矩阵,要求每一列每一行的元素的平方总和是一个平方数. 解题思路:构造.依照 a a a b a a ...

  3. CodeForces 1099E - Nice table - [好题]

    题目链接:https://codeforces.com/problemset/problem/1099/E You are given an $n×m$ table, consisting of ch ...

  4. codeforces 233 C. Cycles(贪心+思维)

    题目链接:http://codeforces.com/contest/233/problem/C 题意:在一个无相图中有N个长度为3 的回路,输出符合条件的图.注意此图的节点数不得超过100 题解:贪 ...

  5. codeforces 582A. GCD Table 解题报告

    题目链接:http://codeforces.com/problemset/problem/582/A 网上很多题解,就不说了,直接贴代码= = 官方题解: http://codeforces.com ...

  6. codeforces D. Multiplication Table

    http://codeforces.com/contest/448/problem/D 题意:一个n×m的矩阵,a[i][j]=i*j; 然后把a数组排序,找出第k个数. 思路:1-n×m二分枚举,然 ...

  7. Codeforces 22B Bargaining Table

    http://www.codeforces.com/problemset/problem/22/B 题意:求出n*m的方格图中全是0的矩阵的最大周长 思路:枚举 #include<cstdio& ...

  8. Codeforces #662C Binary Table

    听说这是一道$ Tourist$现场没出的题 Codeforces #662C 题意: 给定$n*m的 01$矩阵,可以任意反转一行/列($0$变$1$,$1$变$0$),求最少$ 1$的数量 $ n ...

  9. Codeforces 40E Number Table - 组合数学

    题目传送门 传送门I 传送门II 题目大意 给定一个$n\times m$的网格,每个格子上要么填$1$,要么填$-1$,有$k$个位置上的数是已经填好的,其他位置都是空的.问有多少种填法使得任意一行 ...

随机推荐

  1. Java类型信息

    一.引言 最近在阅读<Java编程思想>,学习一下java类型信息,现在做一下总结.Java如何让我们在运行时识别对象和类的信息的.主要有两种方式:一种是传统的“RTTI”,它假定我们在编 ...

  2. MFC中的CString类使用方法指南

    MFC中的CString类使用方法指南 原文出处:codeproject:CString Management [禾路:这是一篇比较老的资料了,但是对于MFC的程序设计很有帮助.我们在MFC中使用字符 ...

  3. ubuntu----VMware 鼠标自由切换问题及主机虚拟机共享剪切板问题

    VMware 安装了Ubuntu之后,在正常安装了VMware tools后,仍然不能正常的在Ubuntu与物理机之间自由的切换,每次都要按下ctrl+Alt,而且鼠标指针会经常性的离奇的失灵 解决方 ...

  4. 如何利用好github的问题

    github对我来说真的是一个超好的平台,不过之前只是把它仓库来使用, 后来在大佬告诉我应该怎么使用github,今天就来总结下如何利用好github,让它发挥最大的威力. 1.把github当做百科 ...

  5. Codeforces 866C Gotta Go Fast - 动态规划 - 概率与期望 - 二分答案

    You're trying to set the record on your favorite video game. The game consists of N levels, which mu ...

  6. Codeforces Round #439 (Div. 2) Problem A (Codeforces 869A) - 暴力

    Rock... Paper! After Karen have found the deterministic winning (losing?) strategy for rock-paper-sc ...

  7. Bootstrap3基础 form-inline 输入框在同一行

      内容 参数   OS   Windows 10 x64   browser   Firefox 65.0.2   framework     Bootstrap 3.3.7   editor    ...

  8. 【做题】51NOD1518 稳定多米诺覆盖——容斥&dp

    题意:求有多少种方案,用多米诺骨牌覆盖一个\(n\times m\)的棋盘,满足任意一对相邻行和列都至少有一个骨牌横跨.对\(10^9+7\)取模. \(n,m \leq 16\) 首先,这个问题的约 ...

  9. IDEA 入门

    IDEA初步使用 IntelliJ IDEA 使用教程(2019图文版) -- 从入门到上瘾 IntelliJ IDEA 设置代码提示或自动补全的快捷键 (Alt+/) IntelliJ IDEA 配 ...

  10. 题解——loj6281 数列分块入门5 (分块)

    分块 若块内最大值为0或1,则不用再开方 然后暴力修改 可以证明,如果开方后向下取整,则最多开方4次一个数就会变成0或1 #include <cstdio> #include <cm ...