Description

一个A和两个B一共可以组成三种字符串:"ABB","BAB","BBA".
给定若干字母和它们相应的个数,计算一共可以组成多少个不同的字符串.
 

Input

每组测试数据分两行,第一行为n(1<=n<=26),表示不同字母的个数,第二行为n个数A1,A2,...,An(1<=Ai<=12),表示每种字母的个数.测试数据以n=0为结束.
 

Output

对于每一组测试数据,输出一个m,表示一共有多少种字符串.
 

Sample Input

2
1 2
3
2 2 2
0
 

Sample Output

3
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题目————字串数的更多相关文章

  1. 字串数_hdu_1261(大数极致).java

    字串数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submis ...

  2. HDOJ 1261 字串数

    JAVA大数.... 字串数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  3. HDU 1261 字串数(排列组合)

    字串数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...

  4. 题解报告:hdu 1261 字串数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1261 Problem Description 一个A和两个B一共可以组成三种字符串:"ABB ...

  5. hdu 1261 字串数

    解题思路:ACM紫书 第十章 P319 有重复元素的全排列 答案: 所有数的和的阶乘 除以 每个数阶乘的乘积 因为给定 (26*12)! 会爆掉(long long),这里用java 的BigInte ...

  6. 【字符串】BZOJ上面几个AC自动机求最为字串出现次数的题目

    (一下只供自己复习用,目的是对比这几个题,所以写得不详细.需要细节的可以参考其他博主) [BZOJ3172:单词] 题目: 某人读论文,一篇论文是由许多(N)单词组成.但他发现一个单词会在论文中出现很 ...

  7. hdu 4333 扩展kmp+kmp重复字串去重

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4333 关于kmp next数组求最短重复字串问题请看:http://www.cnblogs.com/z ...

  8. Day07 - Ruby比一比:Symbol符号与String字串

    前情提要: 第六天我们透过Ruby代码练习public,protected和privatemethod时,发现冒号在前面的参数,:mydraft,:myspace,这些就是符号Symbol.在今天,我 ...

  9. POJ - 2774~POJ - 3415 后缀数组求解公共字串问题

    POJ - 2774: 题意: 求解A,B串的最长公共字串 (摘自罗穗骞的国家集训队论文): 算法分析: 字符串的任何一个子串都是这个字符串的某个后缀的前缀. 求 A 和 B 的最长 公共子串等价于求 ...

随机推荐

  1. 测试App运行状态

    示例代码: #import "AppDelegate.h" @interface AppDelegate () @end @implementation AppDelegate - ...

  2. Linux-QT 开发环境搭建以及编译镜像

    搭建Linux-QT 开发环境,需要先搭建Android 的编译环境,然后在Android 编译环境的基础上,再搭建Linux-QT 编译环境. 第一:编译器. 第二:设置环境变量.环境变量设置后,编 ...

  3. Leetcode: Data Stream as Disjoint Intervals && Summary of TreeMap

    Given a data stream input of non-negative integers a1, a2, ..., an, ..., summarize the numbers seen ...

  4. zabbix监控路由器所有接口信息

    zabbix监控路由器所有接口信息 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 1.首先在服务器端安装snmp工具 [root@bogon yinzhengjie]# yum - ...

  5. 树链剖分(单点更新,求区间最值,区间求和Bzoj1036)

    1036: [ZJOI2008]树的统计Count Time Limit: 10 Sec  Memory Limit: 162 MB Submit: 5759  Solved: 2383 [Submi ...

  6. uva 11178 - Morley's Theorem

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  7. linux环境变量与本地变量

    两者不同的是. 环境变量可以在shell的子进程中使用, 而本地变量不同. 每当连接上服务器时,服务器就会通过帐号密码运行一个SHELL,我们所做的工作都在这个SHELL上,特殊方法除外(如,守护进程 ...

  8. II7下配置SSAS通过HTTP 远程链接访问

    IIS7下配置SSAS通过HTTP远程连接 安装环境操作系统:Windows7.Windows Server2008IIS版本:7.5 IIS7下配置SSAS通过HTTP远程连接详细的步骤如下:1.首 ...

  9. 使用console进行 性能测试 和 计算代码运行时间(转载)

    本文转载自: 使用console进行 性能测试 和 计算代码运行时间

  10. 安装交叉编译器arm-linux-gcc

    需要交叉编译环境故安装交叉编译环境    1.在宿主机的/usr/local/arm目录存放交叉编译器        mkdir /usr/local/arm    2.解压交叉编译器包至/usr/l ...