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$个位置上的数是已经填好的,其他位置都是空的.问有多少种填法使得任意一行 ...
随机推荐
- Django设计模式
单例模式: 建造者模式: 示例: from enum import Enum import time PizzaProgress = Enum('PizzaProgress', 'queued pre ...
- 实现 AD 采样,使用 LCD1602 显示 AD 数值
实现 AD 采样,使用 LCD1602 显示 AD 数值 写在前面 单片机内集成的A/D转换,一般都有相应的特殊功能寄存器来设置A/D的使能标志,参考电压,转换频率,通道选择,A/D输入口的属性(模拟 ...
- Redis热点Key发现及常见解决方案!
一.热点Key问题产生的原因 1.用户消费的数据远大于生产的数据(热卖商品.热点新闻.热点评论.明星直播). 在日常工作生活中一些突发的的事件,例如:双十一期间某些热门商品的降价促销,当这其中的某一件 ...
- 20145319 《计算机病毒》动态分析lab3-2
20145319 <计算机病毒>动态分析lab3-2(实践六) 实践过程 基础分析 拿到恶意代码时,首先使用PE ID打开,查看其中一些基础信息以及观察该恶意代码是否加壳,来确定下一步分析 ...
- 基于快速排序思想partition查找第K大的数或者第K小的数。
快速排序 下面是之前实现过的快速排序的代码. function quickSort(a,left,right){ if(left==right)return; let key=partition(a, ...
- libcurl 静态库编译
转载:http://www.cnblogs.com/jkcx/p/6406706.html 1.下载最新版的libcurl(官网:http://curl.haxx.se/download.html), ...
- 【python35.2--图形用户界面EasyGui】
一.猜字游戏 #猜字游戏(从1到10) import easygui as g import random g.msgbox('欢迎进入探险之路!') screct = random.randint( ...
- main.dart
import 'package:flutter/material.dart'; import 'package:flysnow_2ull/index/index.dart'; // 导入index.d ...
- Python 处理 CSV/EXCEL 表格文件
只想说,数据挖掘工作,80%时间都花在处理数据上了,这句话真不假! 最近和小伙伴组了个队参加数据分析比赛,记录下我处理 csv 文件的一些步骤吧: 修改csv文件 可以用csv模块1,官方文档2 im ...
- 彻底了解 suid, sgid ,sticky权限
sticky: 粘性的, 如 : sticky tape: 粘胶带 /tmp, /var/tmp: 位 sticky: 表示: 第一, 任何用户都可以在该目录下创建文件(编辑自己的文件),第二, 但是 ...