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 ...
随机推荐
- jQuery实现鼠标移到元素上动态提示消息框效果
当光标移动到某些元素上时,会弹出像tips的提示框,这种效果想必大家都有见到过吧,下面有个不错的示例,大家可以感受下 当光标移动到某些元素上时,会弹出像tips的提示框. 复制代码代码如下: < ...
- 005.ClearStoredGroups方法
Delphi procedure ClearStoredGroups; 类型:procedure 可见性:protected 所在单元:System.RegularExpressionsCore 父类 ...
- 学习hash_map从而了解如何写stl里面的hash函数和equal或者compare函数
---恢复内容开始--- 看到同事用unordered_map了所以找个帖子学习学习 http://blog.sina.com.cn/s/blog_4c98b9600100audq.html (一)为 ...
- C语言小结之结构类型
C语言小结之结构类型 @刁钻的游戏 (1)枚举型类型enum COLOR {BLACK,RED,BLUE};//声明一种新的数据类型,其值分别为0,1,2但是用BLACK/RED/BLUE代表也可以这 ...
- Oracle分析函数之FIRST_VALUE和LAST_VALUE
FIRST_VALUE 返回组中数据窗口的第一个值 FIRST_VALUE ( [scalar_expression )OVER ( [ partition_by_clause ] order_by_ ...
- 一步步学习NHibernate(3)——NHibernate增删改查
请注明转载地址:http://www.cnblogs.com/arhat 在上一章中,我们配置了以下NHibernate的运行环境, 并介绍了NHibernate的中两个非常中重要的接口"I ...
- BZOJ Tyvj 1729 文艺平衡树
Description 您需要写一种数据结构(可参考题目标题),来维护一个有序数列,其中需要提供以下操作:翻转一个区间,例如原有序序列是5 4 3 2 1,翻转区间是[2,4]的话,结果是5 2 3 ...
- WIN32api总结
1.鼠标操作: win32api.SetCursorPos((101,156)) win32api.mouse_event(win32con.MOUSEEVENT_LEFTDOWN,0,0,0,0) ...
- ubuntu安装svn manager
环境:系统ubuntu14.04 0. 更新软件库 sudo apt-get update sudo apt-get upgrade -y 1. 安装apache,svn,svn的apache模块 s ...
- 1088-Gnome Sequencing
描述 In the book All Creatures of Mythology, gnomes are kind, bearded creatures, while goblins tend to ...