UVA 11076 Add Again 计算对答案的贡献+组合数学
A pair of numbers has a unique LCM but a single number can be the LCM of more than one possible
pairs. For example 12 is the LCM of (1, 12), (2, 12), (3,4) etc. For a given positive integer N, the
number of different integer pairs with LCM is equal to N can be called the LCM cardinality of that
number N. In this problem your job is to find out the LCM cardinality of a number.
Input
The input file contains at most 101 lines of inputs. Each line contains an integer N (0 < N ≤ 2 ∗ 109
).
Input is terminated by a line containing a single zero. This line should not be processed.
Output
For each line of input except the last one produce one line of output. This line contains two integers
N and C. Here N is the input number and C is its cardinality. These two numbers are separated by a
single space.
Sample Input
2
12
24
101101291
0
Sample Output
2 2
12 8
24 11
101101291 5
题意:给出一个序列,要求将所有可能的序列每个序列形成的数值相加的和。
题解:计算每个位置上可能放的数是哪些,计算对答案的贡献的一种,利用到了组合数学,可以类似求杨辉三角去求组合数
//meek///#include<bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include<iostream>
#include<bitset>
#include<map>
using namespace std ;
#define mem(a) memset(a,0,sizeof(a))
#define pb push_back
#define fi first
#define se second
#define MP make_pair
typedef long long ll; const int N = ;
const int M = ;
const int inf = 0x3f3f3f3f;
const int MOD = ;
const double eps = 0.000001; ll ans,c[N][N];
int a[N],v[N],n;
ll add(){
int k = n-;
ll t = ;
for(int i=;i<;i++) {
t *= c[k][v[i]];
k -= v[i];
}
return t;
}
int main() {
for(int i=;i<=;i++) {
c[i][] = ;
for(int j=;j<=i;j++)
c[i][j] = c[i-][j-] + c[i-][j];
}
while(~scanf("%d",&n)) {
if(n==)break;
mem(v);ans = ;
ll sum = ;
for(int i=;i<=n;i++) scanf("%d",&a[i]),v[a[i]]++;
for(ll i=;i<=;i++) {
if(v[i]) {
v[i]--;
ll tmp = add();
v[i]++;
sum += i*tmp;
}
}
ans = ;
for(int i=;i<=n;i++) ans = ans* + sum;
printf("%lld\n",ans);
}
return ;
}
代码
UVA 11076 Add Again 计算对答案的贡献+组合数学的更多相关文章
- ZOJ 3872 计算对答案的贡献
D - Beauty of Array Description Edward has an array A ...
- UVA 11038 - How Many O's? 计算对答案的贡献
题意: 求[n, m]之间包含0的数字的个数题解:转化为求solve(n) - solve(m-1)的前缀问题 对于求0到n的解,我们举例 n = 25789 对于8这位,让其为0对答案的贡献是 (0 ...
- 【数论-数位统计】UVa 11076 - Add Again
Add AgainInput: Standard Input Output: Standard Output Summation of sequence of integers is always a ...
- UVA 11076 - Add Again(组合)
题目链接 脑子抽了,看错题了,神奇的看成没有0了.主要问题把n个数插入m个相同的数,把m个数给分成1-m堆,然后插到n+1空里. #include <cstdio> #include &l ...
- 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) 对于任意一个数字,其在每一位出现的次数是相同的 即所有数字的每一位相加的和是相同的. 因此可以等效为它们 ...
- 数论 UVA 11076
这道题目的意思简单易懂说的是给你n个数(可能有重复相同的数字),列出他们所有排列的情况,再逐位相加,求出和,例如:给你1,2,3,则排列的情况为<123>, <132>, &l ...
随机推荐
- Controltemplate datatemplate
DataTemplate ControlTemplate we can search many posts about this topic. some valuable link: DataTemp ...
- 3-附1 ->和*的区别
问题: c++ .和 ->有什么区别? 还有什么是继承什么是派生?-------------------------------------------------------------- 比 ...
- Java Day 13
线程的状态 被创建 运行 冻结 消亡 被创建--start()--> 运行 运行----run()----> 消亡 stop() 运行---sleep(time)---& ...
- 1.1 MySQL 逻辑架构
- Unity3d之Animation(动画系统)
1,动画系统配置,2,代码控制动画 原文地址: http://blog.csdn.net/dingkun520wy/article/details/51247487 1,动画系统配置 创建游戏对象并添 ...
- ASP.Net MVC利用NPOI导入导出Excel
因近期项目遇到所以记录一下: 首先导出Excel: 首先引用NPOI包 http://pan.baidu.com/s/1i3Fosux (Action一定要用FileResult) /// <s ...
- WordPress按钮秒支付插件发布,支持微信支付,支付宝,银联,京东,苏宁,易宝支付
痛点: 我们用WordPress建设网站和开发移动应用,有时候我们其实不需要太多的流程,只是需要一个收款通道,但是可能对支持的渠道更加关注,特别是手机应用.所以WordPress按钮秒支付插件诞生了, ...
- python 数据结构-元组tuple
tuple0=() #空 tuple1="wo", #元组中包括单个元素用, tuple2="monkey","cat","chi ...
- Nginx问题总汇
http://blog.csdn.net/llnara/article/details/8691049 关键字: open var run nginx pid failed 产生原因:添加模块,重编译 ...
- Ext通过后台校验字段是否重复
话不多说,直接上代码: handlerRybh : function(textField) { Ext.Ajax.request({// ajax请求的方法 url : 'userManage/per ...