UVA 11076 - Add Again(组合)
脑子抽了,看错题了,神奇的看成没有0了。主要问题把n个数插入m个相同的数,把m个数给分成1-m堆,然后插到n+1空里。
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <iostream>
using namespace std;
#define MOD 1000000
#define LL long long
LL c[][];
int p[];
int n;
LL judge()
{
LL ans = ;
int i,j,pre = ;
LL temp;
for(i = ;i < ;i ++)
{
if(p[i])
{
temp = ;
for(j = ;j <= p[i];j ++)
{
temp += c[pre+][j]*c[p[i]-][j-];
}
ans *= temp;
pre += p[i];
}
}
return ans;
}
int main()
{
int i,j,num;
LL ans,temp;
for(i = ;i <= ;i ++)
c[i][] = ;
for(i = ;i <= ;i ++)
{
for(j = ;j <= ;j ++)
c[i][j] = c[i-][j-] + c[i-][j];
}
while(cin>>n)
{
if(!n) break;
memset(p,,sizeof(p));
ans = ;
for(i = ;i < n;i ++)
{
cin>>num;
p[num] ++;
}
temp = ;
for(i = ;i < n;i ++)
{
temp = temp* + ;
}
for(i = ;i < ;i ++)
{
if(p[i])
{
p[i] -- ;
ans += i*temp*judge();
p[i] ++;
}
}
cout<<ans<<endl;
}
return ;
}
UVA 11076 - Add Again(组合)的更多相关文章
- UVA 11076 Add Again 计算对答案的贡献+组合数学
A pair of numbers has a unique LCM but a single number can be the LCM of more than one possiblepairs ...
- 【数论-数位统计】UVa 11076 - Add Again
Add AgainInput: Standard Input Output: Standard Output Summation of sequence of integers is always a ...
- Uva 11076 Add Again (数论+组合数学)
题意:给你N个数,求把他们的全排列加和为多少 思路:对于这道题,假设数字k1在第一位,然后求出剩下N-1位的排列数num1,我们就可以知道k1在第一位时 排列有多少种为kind1, 同理,假设数字k2 ...
- UVA 11076 Add Again
题目链接:UVA-33478 题意为给定n个数,求这n个数能组成的所有不同的排列组成的数字的和. 思路:发现对于任意一个数字,其在每一位出现的次数是相同的.换言之,所有数字的每一位相加的和是相同的. ...
- UVa 11076 (有重元素的排列) Add Again
n个可重复的元素的排列一共有 = All种,其中 假设这些数依次为ai,每种数字有mi个. 从右往左考虑第d位数(d≥0),第i个数字出现的次数为,那么这个数字对所求答案的贡献为 其实可以先一次求出个 ...
- Add Again UVA - 11076(排列之和)
题意: 输入n个数字,求这些数字 所有全排列的和 (1<= n <= 12) 对于任意一个数字,其在每一位出现的次数是相同的 即所有数字的每一位相加的和是相同的. 因此可以等效为它们 ...
- 【NOIP合并果子】uva 10954 add all【贪心】——yhx
Yup!! The problem name reects your task; just add a set of numbers. But you may feel yourselvesconde ...
- UVA 10954 Add All 哈夫曼编码
题目链接: 题目 Add All Time Limit:3000MS Memory Limit:0KB 问题描述 Yup!! The problem name reflects your task; ...
- UVA - 11916 Emoogle Grid (组合计数+离散对数)
假如有这样一道题目:要给一个M行N列的网格涂上K种颜色,其中有B个格子不用涂色,其他每个格子涂一种颜色,同一列中的上下两个相邻格子不能涂相同颜色.给出M,N,K和B个格子的位置,求出涂色方案总数除以1 ...
随机推荐
- Linux环境下stl库使用(vector)
step1: #include <iostream> #include <vector> #include <string> using namespace std ...
- PGA
Server Process PGA 1.PGA作用 2.PGA構成 1)private sql area 2)session memory 3)sql ...
- ORA-03113:通信通道的文件结尾解决
今天跟往常一样,登陆PL/SQL,确登陆失败,出现一个错误“ORA-01034”和“ORA-27101”如图: 然后就就通过命令提示符去登陆Oracle,去查看怎么回事,然后问题进一步出现,错误“OR ...
- phpcms调用一级栏目和二级栏目
{loop subcat(,,,$siteid) $r} {php $num++} <strong><a href=} <br /> {elseif $n!=$c} | ...
- [CentOS]安装软件:/lib/ld-linux.so.2: bad ELF interpreter解决
转自:http://blog.csdn.net/wanglei2258/article/details/24961233 [CentOS]安装软件:/lib/ld-linux.so.2: bad EL ...
- 完善SQL农历转换函数
-------------------------------------------------------------------- -- Author : 原著: 改编:ht ...
- 【转】Kylin实践之使用Hive视图
http://blog.csdn.net/yu616568/article/details/50548967 为什么需要使用视图 Kylin在使用的过程中使用hive作为cube的输入,但是有些情况下 ...
- HDU 4496 D-City (并查集)
题意:有n个城市,m条路,首先m条路都连上,接着输出m行,第i行代表删除前i行的得到的连通块个数 题解:正难则反,我们反向考虑使用并查集添边.首先每个点都没有相连,接着倒着来边添加边计算,当两个点父节 ...
- hdu1003 dp
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1003 #include<cstdio> #include<algorit ...
- js:方法2. 字符串
String.charAt()/String.charCodeAt() string.charAt(n); n:The index of the character that should be re ...