当前位置:网站首页>[Acwing] 第 60 场周赛 C-AcWing 4496. 吃水果
[Acwing] 第 60 场周赛 C-AcWing 4496. 吃水果
2022-07-17 12:39:00 【*DDL_GzmBlog】
前言
t a g : tag : tag:组合数学dp
题意 :
给定 n n n个人, m m m个水果,询问恰好有 k k k个人拿到的水果和左边的人不一样的方案数
组合思路 :
我们在 n − 1 n-1 n−1个人中挑选出 k k k个人
显然第一个人有 m m m种选法,那么剩下的要么是和第一个人相同要么就是不同
因此总共有 ( m − 1 ) k (m-1)^k (m−1)k种选法,而对应这 k k k个人又有 C n − 1 k C_{n-1}^k Cn−1k种
所以总方案数 C n − 1 k ∗ m ∗ ( m − 1 ) k C_{n-1}^k*m*(m-1)^k Cn−1k∗m∗(m−1)k
code :
ll qmi(ll a,ll b){
ll res = 1;
while(b){
if(b&1) res = res*a%mod;
a = a*a%mod;
b>>=1;
}
return res;
}
ll f(ll x){
ll res = 1;
for(ll i=1;i<=x;i++) res = res*i%mod;
return res%mod;
}
ll inv(ll x){
return qmi(x,mod-2);
}
ll getC(ll a,ll b){
return f(a)*inv(f(a-b)*f(b)%mod)%mod;
}
void solve(){
cin>>n>>m>>k;
cout<<(getC(n-1,k)*m%mod)*qmi(m-1,k)%mod<<endl;
}
dp思路 :
我们设状态
d p [ i ] [ j ] 表示前 i 位有 j 个不同的方案数 dp[i][j]表示前i位有j个不同的方案数 dp[i][j]表示前i位有j个不同的方案数
那么转移很好想到
d p [ i ] [ j ] = d p [ i − 1 ] [ j ] + d p [ i − 1 ] [ j − 1 ] ∗ ( m − 1 ) dp[i][j]=dp[i-1][j]+dp[i-1][j-1]*(m-1) dp[i][j]=dp[i−1][j]+dp[i−1][j−1]∗(m−1)
(前面已经凑出来 j j j个不同 d p [ i − 1 ] [ k ] dp[i-1][k] dp[i−1][k]
(前面只凑出来 j − 1 j-1 j−1个不同,因此当前的选择需要乘上 ( m − 1 ) (m-1) (m−1)
code :
ll dp[N][N];
ll n,m,k;
void solve(){
cin>>n>>m>>k;
for(int i=1;i<=k;i++) dp[1][i] = 0 ;
//第一个不算
for(int i=1;i<=n;i++) dp[i][0]=m;
for(int i=2;i<=n;i++)
for(int j=1;j<=k;j++)
dp[i][j] = (dp[i-1][j]+dp[i-1][j-1]*(m-1)%mod)%mod;
cout<<dp[n][k]<<endl;
}
边栏推荐
- 2022 Shaanxi secondary vocational group "Cyberspace Security" - packet analysis
- String type function transfer problem
- 如何使用SVG制作沿任意路径排布的文字效果
- On the structural types of C language
- string类的介绍及模拟实现
- Domestic flagship mobile phones have a serious price foam, and second-hand phones are more cost-effective than new ones, or buy iPhones
- R language ggplot2 visualization: use the gghistogram function of ggpubr package to visualize the grouping histogram, and use the palette parameter to customize the bar border color of the grouping hi
- The use and Simulation of stack and queue in STL
- TS解决引入插件的类型文件不存在的问题
- R language ggplot2 visualization: use the ggstripchart function of ggpubr package to visualize dot strip plot, and set the add parameter to mean_ SD add the mean standard deviation vertical line and s
猜你喜欢

The use and Simulation of stack and queue in STL

STL中stack和queue的使用以及模拟实现

图神经网络的可解释性方法介绍和GNNExplainer解释预测的代码示例

opencv 画黑色矩形,并写上序号

Detailed explanation of C language custom types

Figure an introduction to the interpretable method of neural network and a code example of gnnexplainer interpreting prediction

NJCTF 2017messager

HCIA OSPF

架构实战营|模块7

【PostgreSQL 】PostgreSQL 15对distinct的优化
随机推荐
How to solve the problem of cross domain access by Google browser
知其然,而知其所以然,JS 对象创建与继承
【Unity技术积累】简易计时器 & 协程 & 延时函数
SAP S4 Material Management 库存模块 MARD 数据库表读取技术细节介绍
R language ggplot2 visualization: use the gghistogram function of ggpubr package to visualize the grouping histogram, and use the palette parameter to customize the bar border color of the grouping hi
【PostgreSQL 】PostgreSQL 15对distinct的优化
麒麟信安操作系统衍生产品解决方案 | 主机安全加固软件,实现一键快速加固!
王者荣耀商城异地多活架构设计
R language ggplot2 visualization: use the ggstripchart function of ggpubr package to visualize dot strip plot, and set the add parameter to mean_ SD add the mean standard deviation vertical line and s
How to realize the association between interfaces in JMeter?
HCIA 静态综合实验报告 7.10
新能源赛道已经高位风险,提醒大家注意安全
2022 Zhejiang secondary vocational group "Cyberspace Security" code information acquisition and analysis (full version)
R语言dplyr包select函数删除dataframe数据中包含指定字符串内容的数据列(drop columns in dataframe)
Stream流
2022 Shaanxi secondary vocational group "Cyberspace Security" - packet analysis
Quick completion guide of manipulator (zero five): resources related to manipulator
圆桌实录:炉边对话——如何在 Web3 实现创新
如何在双链笔记软件中建立仪表盘和知识库?以嵌入式小组件库 NotionPet 为例
c# treeView 树形结构递归处理(企业集团型层次树形展示)