vijosP1413 Valentine’s Present
vijosP1413 Valentine’s Present
【思路】
组合公式。
由题目知:每个箱子中的蛋糕要么与箱子颜色相同,要么指向一个蛋糕与箱子颜色相同的箱子。先从n个箱子中选取i个作为指向自己(箱子蛋糕颜色相同)的箱子,数目为C(n,i),剩下的n-i个箱子每个箱子有i个选择所以方案数为i^(n-i),总的方案数为C(n,i)*i^(n-i),枚举i计和即可。
【代码】
#include<iostream>
using namespace std; int n;
long long C[][];
int MOD=; int main() {
cin>>n;
for(int i=;i<=n;i++) {
C[i][]=C[i][i]=;
for(int j=;j<i;j++) C[i][j]=(C[i-][j]+C[i-][j-])%MOD;
}
int ans=;
for(int i=;i<=n;i++) {
int tmp=;
for(int j=;j<=n-i;j++) tmp=tmp*i%MOD;
ans = (ans+C[n][i]*tmp%MOD)%MOD;
}
cout<<ans;
return ;
}
vijosP1413 Valentine’s Present的更多相关文章
- HDU 6693 Valentine's Day (概率)
2019 杭电多校 10 1003 题目链接:HDU 6693 比赛链接:2019 Multi-University Training Contest 10 Problem Description O ...
- [概率] HDU 2019 Multi-University Training Contest 10 - Valentine's Day
Valentine's Day Time Limit: 2000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others ...
- 跳转时候提示Attempt to present on while a presentation is in progress
出现这种情况,例如:我在获取相册图片后,直接present到另一个页面,但是上一个页面可能还未dismiss,所以,要在获取相册图片的dismiss方法的complete的block里面写获取图片及跳 ...
- find your present (感叹一下位运算的神奇)
find your present (2) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
- HTTP Status 400 - Required String parameter 'userName' is not present 错误
HTTP Status 400 - Required String parameter 'userName' is not present 错误 先mark 有时间详细写 参考链接: https:/ ...
- Linux 克隆虚拟机引起的“Device eth0 does not seem to be present, delaying initialization”
虚拟机Vmware上克隆了一个Red Hat Enterprise Linx启动时发现找不到网卡,如下所示,如果你在命令窗口启动网络服务就会遇到"Device eth0 does not s ...
- required string parameter XXX is not present
@RequestParam jQuery调用方式: deleteFile: function(filePath) { return ajax({ method: 'POST', url: '/cm/s ...
- 启动网卡报:Device eth0 does not seem to be present”解决办法
Device eth0 does not seem to be present”解决办法 : 用ifconfig查看发现缺少eth0,只有lo:用ifconfig -a查看发现多出了eth1的信息. ...
- jQuery 跨域访问的三种方式 No 'Access-Control-Allow-Origin' header is present on the reque
问题: XMLHttpRequest cannot load http://v.xxx.com. No 'Access-Control-Allow-Origin' header is present ...
随机推荐
- RepeatedDNASequences BestTime_to_Buy_and_SellStockIV
/** * @Author: weblee * @Email: likaiweb@163.com * @Blog: http://www.cnblogs.com/lkzf/ * @Time: 2015 ...
- 安装saltstack
1.安装master 安装epel源 # cd /usr/local/src/ # wget http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-rel ...
- VM启动报错:Failed to lock the file
http://www.cnblogs.com/kristain/articles/2491966.html Reason: Failed to lock the fileGoogle 了一下, 在網路 ...
- 10.MVC框架开发(Ajax应用)
1.MVC自带的Ajax应用, 使用步骤: 第一步,引入js框架 <script src="../../Scripts/jquery-1.4.4.js" type=" ...
- [转载]MongoDB开发学习(1)开天辟地,经典入门
原文地址:http://www.cnblogs.com/xumingxiang/archive/2012/04/08/2437468.html 如果你从来没有接触MongoDB或对MongoDB有一点 ...
- MySql排序性能对比
- SecureCRT 中文乱码问题
1.修改远程linux机器的配置 [root@rhel ~]#vi /etc/sysconfig/i18n 把LANG改成支持UTF-8的字符集 如: LANG=”zh_CN.UTF-8″ 或者是 L ...
- iOS开发UI篇—UITabBarController生命周期(使用storyoard搭建)
iOS开发UI篇—UITabBarController生命周期(使用storyoard搭建) 一.UITabBarController在storyoard中得搭建 1.新建一个项目,把storyb ...
- Android RelativeLayout
RelativeLayout为相对布局,这种布局内的组件总是相对兄弟组件.父容器来确定的,在定义控件的位置时,需要参照其他控件的位置. 这个程序实现了一个梅花的相对布局 <?xml versio ...
- Linux网络地址转换分析
Linux网络地址转换分析 地址转换用来改变源/目的端口,是netfilter的一部分,也是通过hook点上注册相应的结构来工作. Nat注册的hook点和conntrack相同,只是优先级不同,数据 ...