vijosP1413 Valentine’s Present

vijosP1413 Valentine’s Present

链接:https://vijos.org/p/1413

【思路】

组合公式。

由题目知:每个箱子中的蛋糕要么与箱子颜色相同,要么指向一个蛋糕与箱子颜色相同的箱子。先从n个箱子中选取i个作为指向自己(箱子蛋糕颜色相同)的箱子,数目为C(n,i),剩下的n-i个箱子每个箱子有i个选择所以方案数为i^(n-i),总的方案数为C(n,i)*i^(n-i),枚举i计和即可。

【代码】

 1 #include<iostream>
 2 using namespace std;
 3
 4 int n;
 5 long long C[30][30];
 6 int MOD=19900801;
 7
 8 int main() {
 9     cin>>n;
10     for(int i=1;i<=n;i++) {
11         C[i][0]=C[i][i]=1;
12       for(int j=1;j<i;j++)  C[i][j]=(C[i-1][j]+C[i-1][j-1])%MOD;
13     }
14     int ans=0;
15     for(int i=1;i<=n;i++) {
16        int tmp=1;
17        for(int j=1;j<=n-i;j++) tmp=tmp*i%MOD;
18        ans = (ans+C[n][i]*tmp%MOD)%MOD;
19     }
20     cout<<ans;
21     return 0;
22 }
时间: 2024-10-12 12:34:29

vijosP1413 Valentine’s Present的相关文章

AIX 5.3 Install Oracle 10g RAC 错误集锦--9i RAC present

AIX 5.3 Install Oracle 10g RAC 错误集锦--9i RAC Present 系统环境: 操作系统: AIX 5300-08 集群软件: CRS 10.2.0.1 数据库:   Oracle 10.2.0.1                     系统架构图 故障现象: 解决方法: [[email protected] tmp]# cat /etc/oratab # This file is used by ORACLE utilities.  It is creat

find your present (感叹一下位运算的神奇)

find your present (2) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 21948    Accepted Submission(s): 8671 Problem Description In the new year party, everybody will get a "special present"

CentOS Linux解决Device eth0 does not seem to be present

在VMware里克隆出来的CentOS Linux.. ifconfig...没有看到eth0..然后重启网卡又报下面错误. 故障现象: service network restartShutting down loopback insterface:                                                                                                     [  OK  ]Bringing up loo

UITabBarController未呈现时present另一个ViewController会发生什么?

一次给了下面两条警告(精彩吧): Presenting view controllers on detached view controllers is discouraged Unbalanced calls to begin/end appearance transitions for <UITabBarController: 0x7fc046131d70>. 解决办法,dispatch_after 延迟present就好了.

Warning: Attempt to present on whose view is not in the window hierarchy!

当我想从一个VC跳转到另一个VC的时候,一般会用 - (void)presentViewController:(UIViewController *)viewControllerToPresent animated: (BOOL)flag completion:(void (^)(void))completion;当然也可以用导航push. 有时会遇到了此类警告:Warning: Attempt to present on whose view is not in the window hier

As.net WebAPI CORS, 开启跨源访问,解决错误No &#39;Access-Control-Allow-Origin&#39; header is present on the requested resource

默认情况下ajax请求是有同源策略,限制了不同域请求的响应. 例子:http://localhost:23160/HtmlPage.html 请求不同源API http://localhost:22852/api/values, What is "Same Origin"? Two URLs have the same origin if they have identical schemes, hosts, and ports. (RFC 6454) These two URLs h

Bringing up interface eth0: Device eth0 does not seem to be present, delaying initialization.

--http://blog.csdn.net/xluren/article/details/38986667 Bringing up interface eth0:  Device eth0 does not seem to be present, delaying initialization. 在linux下的虚拟机出现了这个问题,问题的产生是因为之间做过部分的修改,clone等操作. 不就方案. CentOS Device does not seem to be present  故障现象

杭电2095--find your present (2) (异或)

find your present (2) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 18235    Accepted Submission(s): 7021 Problem Description In the new year party, everybody will get a "special present"

Valentine&#39;s Day Round 1002 Misaki&#39;s Kiss again

题意 Misaki's Kiss again Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 571    Accepted Submission(s): 75 问题描述 摩天轮后,一些朋友希望再次得到Misaki的吻,所以Misaki把他们分别编号从1到N,如果他们中有人的编号是M,而且gcd(N,M)=N xor M,那么他以可以得