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 ...
随机推荐
- 基于jquery的页面代码的优化
高亮显示,选中的文字链接 显示效果如下 默认选择“通知公告”效果 通知公告 学院动态 行业动态 选择“学院动态”效果 通知公告 学院动态 行业动态 选择“行业动态”效果 通知公 ...
- iOS学习之C语言函数指针
通过函数名调用函数: int max = maxValue(4, 5); printf("max = %d\n", max); 函数类型:int (int, int) 1. ...
- Android实现AppWidget、Broadcast动态注册
Android实现AppWidget.Broadcast动态注册 开发工具:Andorid Studio 1.3 运行环境:Android 4.4 KitKat 工程内容 主界面可以编辑广播的信息,点 ...
- 使用git客户端获取shiro
1.进入下载的目标文件夹右键( Git Bash Here )
- WPF——数据绑定(二)绑定方法—绑定本地对象
注意:本人初学WPF,文中表达或技术性问题请勿见怪,欢迎指正,谢谢 标记拓展语法:绑定到本地对象 什么是绑定到本地对象,我个人理解就是实现UI层上两个或多个控件的相互关联,一个控件的状态改变,导致另一 ...
- 使用Log4j进行日志操作
使用Log4j进行日志操作 一.Log4j简介 (1)概述 Log4j是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台.文件.GUI组件.甚至是套接字服 ...
- 用R语言对NIPS会议文档进行聚类分析
一.用R语言建立文档矩阵 (这里我选用的是R x64 3.2.2) (这里我取的是04年NIPS共计207篇文档做分析,其中文档内容已将开头的作者名和最后的参考文献进行过滤处理) ##1.Data I ...
- .net 常用正则表达式
Net中正则表达式的简单使用方法及常见验证判断 判断字符串是只是数字我们可以这样写:return new System.Text.RegularExpressions.Regex(@"^([ ...
- 【Validate Binary Search Tree】cpp
题目: Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is define ...
- bzoj 2599 数分治 点剖分
具体可以见漆子超的论文 /************************************************************** Problem: User: B ...