ACM题目————字串数
Description
给定若干字母和它们相应的个数,计算一共可以组成多少个不同的字符串.
Input
Output
Sample Input
1 2
3
2 2 2
0
Sample Output
90
可以轻易推出公式 :(n1+n2+n3+...nn)!/(n1!*n2!*...*nn!);
因为15!还在long long的范围之内,可以先定义一个数组f[15]保存1~15的阶乘,接着就是将(n1+n2+n3+...nn)!计算出来并存到数组内,接着就是大数除法了(相当于一个大数除一个小数)。
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <cmath>
#include <string>
#include <queue> using namespace std;
#define SIZE 30
typedef long long ll ;
int d[SIZE] ;
int ans[] , f[];
void multiply(int c){
ans[] = ans[] = ;
for(int i = ; i <= c ; ++i){
int r = ;
for(int j = ; j <= ans[] ; ++j){
ans[j] *= i ;
ans[j] += r ;
r = ans[j]/ ;
ans[j] %= ;
}
if(r != ){
while(r){
ans[ans[]+] += r% ;
ans[] = ans[]+ ;
r /= ;
}
}
}
} void divide(int n){
for(int i = ; i < n ; ++i){
if(d[i] == ) continue ;
ll r = ;
for(int j = ans[] ; j > ; --j){
r = r* + ans[j] ;
ans[j] = (int)(r/f[d[i]]) ;
r %= f[d[i]] ;
}
int j = ans[] ;
while(!ans[j--]) ;
ans[] = j+ ;
}
} int main(){
int n ;
f[] = f[] = ;
for(int i = ; i < ; ++i)
f[i] = f[i-]*i ;
while(scanf("%d",&n) && n){
int c = ;
memset(ans,,sizeof(ans)) ;
for(int i = ; i < n ; ++i){
scanf("%d",&d[i]) ;
c += d[i] ;
}
multiply(c) ;
divide(n) ;
for(int i = ans[] ; i > ; --i)
printf("%d",ans[i]) ;
puts("") ;
}
return ;
}
2017-3-4再做这道题,用了Java~~哈哈
import java.math.BigInteger; /**
*
* @author Asimple
*
*/ import java.util.Scanner;
public class Main{
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int n;
while( sc.hasNext() ) {
n = sc.nextInt();
if( n == 0 ) break;
int sum = 0;
BigInteger a = BigInteger.valueOf(1);
for(int i=0; i<n; i++) {
int num = sc.nextInt();
sum += num;
a = a.multiply(dd(num));
}
BigInteger b = dd(sum);
b = b.divide(a);
System.out.println(b.toString());
}
} public static BigInteger dd(int x) {
BigInteger a = BigInteger.valueOf(1) ;
for(int i=2; i<=x; i++) {
a = a.multiply(BigInteger.valueOf(i));
}
return a;
}
}
ACM题目————字串数的更多相关文章
- 字串数_hdu_1261(大数极致).java
字串数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
- HDOJ 1261 字串数
JAVA大数.... 字串数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- HDU 1261 字串数(排列组合)
字串数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- 题解报告:hdu 1261 字串数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1261 Problem Description 一个A和两个B一共可以组成三种字符串:"ABB ...
- hdu 1261 字串数
解题思路:ACM紫书 第十章 P319 有重复元素的全排列 答案: 所有数的和的阶乘 除以 每个数阶乘的乘积 因为给定 (26*12)! 会爆掉(long long),这里用java 的BigInte ...
- 【字符串】BZOJ上面几个AC自动机求最为字串出现次数的题目
(一下只供自己复习用,目的是对比这几个题,所以写得不详细.需要细节的可以参考其他博主) [BZOJ3172:单词] 题目: 某人读论文,一篇论文是由许多(N)单词组成.但他发现一个单词会在论文中出现很 ...
- hdu 4333 扩展kmp+kmp重复字串去重
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4333 关于kmp next数组求最短重复字串问题请看:http://www.cnblogs.com/z ...
- Day07 - Ruby比一比:Symbol符号与String字串
前情提要: 第六天我们透过Ruby代码练习public,protected和privatemethod时,发现冒号在前面的参数,:mydraft,:myspace,这些就是符号Symbol.在今天,我 ...
- POJ - 2774~POJ - 3415 后缀数组求解公共字串问题
POJ - 2774: 题意: 求解A,B串的最长公共字串 (摘自罗穗骞的国家集训队论文): 算法分析: 字符串的任何一个子串都是这个字符串的某个后缀的前缀. 求 A 和 B 的最长 公共子串等价于求 ...
随机推荐
- RMQ (Range Minimal Query) 问题 ,稀疏表 ST
RMQ ( 范围最小值查询 ) 问题是一种动态查询问题,它不需要修改元素,但要及时回答出数组 A 在区间 [l, r] 中最小的元素值. RMQ(Range Minimum/Maximum Query ...
- spring 小结
第一步:配置 web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xs ...
- PhantomJS:基于WebKit、开源的服务器端JavaScript API
PhantomJS是一个基于WebKit的服务器端JavaScript API,它基于 BSD开源协议发布.PhantomJS无需浏览器的支持即可实现对Web的支持,且原生支持各种Web标准,如DOM ...
- Lintcode: Segment Tree Query II
For an array, we can build a SegmentTree for it, each node stores an extra attribute count to denote ...
- Lintcode: Remove Node in Binary Search Tree
iven a root of Binary Search Tree with unique value for each node. Remove the node with given value. ...
- SQL 数据库基础
SQL:Structured Quety Language SQL SERVER是一个以客户/服务器(c/s)模式访问.使用Transact-SQL语言的关系型数据库管理子系统(RDBMS) DBMS ...
- ACdream 1157 Segments(CDQ分治)
题目链接:http://acdream.info/problem?pid=1157 Problem Description 由3钟类型操作:1)D L R(1 <= L <= R < ...
- ZOJ 2112 Dynamic Rankings(主席树の动态kth)
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2112 The Company Dynamic Rankings ...
- ls -l 列表信息详解
我们平时用ls -l 命令查看一个目录下的文件和子目录的详悉信息时,会得到一个详细的文件和目录名列表.这个列表包含了文件的属性,所属用户,所属组,创建时间,文件大小等等信息.这些信息到底是什么意思呢? ...
- JSon_零基础_002_将List类型数组转换为JSon格式的对象字符串,返回给界面
将List类型数组转换为JSon格式的对象字符串,返回给界面 所需要导入的包: 编写bean: package com.west.webcourse.po; /** * 第01步:编写bean类, * ...