Number Sequence

Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 895 Accepted Submission(s):
374

Problem Description
Given a number sequence
b1,b2…bn.
Please count how many number
sequences a1,a2,...,an satisfy the condition
that
a1*a2*...*an=b1*b2*…*bn
(ai>1).
 
Input
The input consists of multiple test cases.
For each
test case, the first line contains an integer n(1<=n<=20). The second line
contains n integers which indicate b1,
b2,...,bn(1<bi<=1000000,
b1*b2*…*bn<=1025).
 
Output
For each test case, please print the answer module 1e9
+ 7.
 
Sample Input
2
3 4
 
Sample Output
4
 
 
Hint

For the sample input, P=3*4=12.

Here are the number sequences
that satisfy the condition: 2 6 3 4 4 3 6 2
 

题意:
给定b1---bn n个数,让你求出满足a1*a2*....*an-1*an(ai>1)=b1*b2*...*bn的种数。

思路:
先对每一个b分解质因数,统计每个质因子的个数,每个质因数不相互影响,可以单独考虑。首先考虑一种质因数放的总数,应明白 m个相同的数放进n个不同的盒子中(盒子可以为空)的总的种数为C(n-1,n+m-1).运用隔板法:实际上就是把m个数分成n组,每组可以为空,我们加上n-1个隔板,选出隔板所在的位置,相邻隔板之间的位置都放数,就有C(n-1,n+m-1)种了。
对每一质因数,运用上面的公式分别放进n个不同的盒子中,然后根据乘法原理,就能计算出答案了。

但是此时计算的答案并不是我们想要的,因为ai不能为1,故盒子不能为空,所以要用到容斥原理了。
运用容斥原理加上0盒子个为空的情况,减去k1*1个盒子为空的情况加上k2*2个盒子为空的情况...

k1、k2、ki怎样得到呢?
设 f[i]-放入i个数能够为空的种数,g[i]-放入i个数不能为空的种数,求g[n]。

考虑n=3时,
f[3]=g[3]+C(3,1)*g[2]+C(3,2)*g[1],
f[2]=g[2]+C(2,1)*g[1],
f[1]=g[1].
化简能得到g[3]=f[3]-C(3,1)*f[2]+C(3,2)*f[1].
根据数学归纳法能得到g[n]=f[n]-C(n,1)*f[n-1]+C(n,2)*f[n-2]-...

ps:http://acm.hdu.edu.cn/showproblem.php?pid=4390

#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm> using namespace std; #define FOR(i,a) for((i)=0;i<(a);(i)++)
#define MEM(a) (memset((a),0,sizeof(a)))
#define LL __int64 const int N=;
const int M=;
const LL MOD=;
const int INF=0x7fffffff;
const double eps=1e-;
const double PI=acos(-1.0); LL n,k,f[N],p[N],c[][];
//c记录组合数,f记录因子,p记录对应因子数 void init()//组合数[下a C b上] C(a,b)=C(a-1,b)+C(a-1,b-1);公式递归;
{
for(LL i=;i<=;i++)
{
c[i][]=c[i][i]=;
for(LL j=;j<i;j++)
c[i][j]=(c[i-][j]+c[i-][j-])%MOD;
}
} LL work()
{//容斥原理
LL temp,ans;
ans=;
for(LL i=;i<n;i++)
{
temp=c[n][i];
for(LL j=;j<k;j++)
temp=(temp*c[n-i+p[j]-][n-i-])%MOD;//c(n+m-1,n-1)
if(i% == )
ans=(ans+temp)%MOD;
else
ans=((ans-temp)%MOD+MOD)%MOD;;
}
return ans;
} void Join(LL i,LL t)
{
LL j;
for(j=;j<k;j++)
if(f[j] == i)
{
p[j]+=t;
break;
}
if(j == k)
{
f[k]=i;
p[k++]=t;
}
}
int main()
{
init();
LL a,i,j,t;
while(scanf("%I64d",&n)!=EOF)
{
k=;
for(i=;i<n;i++)
{
scanf("%I64d",&a); //求质因数及个数 t=;
for(j=;j*j<=a;j++)
{
while(a%j==)
{
a/=j;
t++;
}
if(t>)
Join(j,t);
}
if(a>)
Join(a,);
} printf("%I64d\n",work());
}
return ;
}

思路篇,需要好好体会。。。

 

Number Sequence(hdu4390)的更多相关文章

  1. HDU 1711 Number Sequence(数列)

    HDU 1711 Number Sequence(数列) Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...

  2. HDU 1005 Number Sequence(数列)

    HDU 1005 Number Sequence(数列) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...

  3. ACM—Number Sequence(HDOJ1005)

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1005 主要内容: A number sequence is defined as follows: f ...

  4. HDU 1711 Number Sequence(KMP)附带KMP的详解

    题目代号:HDU 1711 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1711 Number Sequence Time Limit: 10000/ ...

  5. Number Sequence (HDoj1005)

    Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1 ...

  6. Number Sequence(kmp)

        Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  7. 1005 Number Sequence(HDU)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1005 Number Sequence Time Limit: 2000/1000 MS (Java/O ...

  8. POJ - 1019 Number Sequence (思维)

    https://vjudge.net/problem/POJ-1019 题意 给一串1 12 123 1234 12345 123456 1234567 12345678 123456789 1234 ...

  9. HDU 1005 Number Sequence (模拟)

    题目链接 Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f( ...

随机推荐

  1. [UWP开发] 在低版本中使用亚克力刷以及部分高版本控件

    写于2018.10.3 仅在我的PC(17763)和WP(Limia 950 XL 15254)上测试过 微软在build 16299中引入了亚克力刷,但是Win10m并没有活那么久,lumia手机在 ...

  2. 配置文件springmvc.xml

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  3. python常用代码片段

    目录 Python3常用 文件处理 json处理 log日志 argparse使用 INIparser Python3常用 文件处理 class BaseMethod: @staticmethod d ...

  4. .NET Core 从1.1升级到2.0记录(Cookie中间件踩坑)

    .NET Core 2.0 新时代 万众瞩目的.NET Core 2.0终于发布了,原定于9.19的dotnetconf大会的发布时间大大提前了1个月,.NET Core 2.0/.NET Stand ...

  5. springboot常用注解

    @SpringBootApplication:包含了@ComponentScan.@Configuration和@EnableAutoConfiguration注解.其中@ComponentScan让 ...

  6. 6_文件IO

    1. 基本文件读取         readline(),readlines(),write(),writelines()         f.read(size),指定读取文件的字节数,需要注意的是 ...

  7. POJ 2707

    #include<iostream> #include<stdio.h> #include<algorithm> using namespace std; int ...

  8. flask开发的CMS管理系统

    Dohoom 详细介绍 Dohoom 基于Python3 Flask +Mysql+ Redis开发的一个Web系统 可用于搭建(开发)个人网站, 企业官网.包含:相册模块,文章模块,小组模块,私信模 ...

  9. Redhat/CentOS 制作本地yum源

    一.制作本地yum源的场景有: (1) 操作系统ISO文件是通过光驱读取的 (2) 操作系统ISO文件是通过USB设备挂载的 (3) 操作系统ISO文件是被上传到本地文件夹的形式 二. 这3种配置方式 ...

  10. ajex 相关参数

    1.url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. 2.type: 要求为String类型的参数,请求方式(post或get)默认为get.注意其他http请求方法,例如 ...