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. 新建WebAPI项目时遇到的问题

    1   处理程序“ExtensionlessUrlHandler-Integrated-4.0”在其模块列表中有一个错误模块“ManagedPipelineHandler” 以管理员运行下面的命令注册 ...

  2. day 74 vue 2 axios数据请求 以及组件的学习

    前情提要:   vue 学习二: 一: 通过axios实现数据请求 1:json数据语法 json数据对象类似于JavaScript中的对象,但是它的键对应的值里面是没有函数方法的,值可以是普通变量, ...

  3. python 结巴分词简介以及操作

    中文分词库:结巴分词 文档地址:https://github.com/fxsjy/jieba 代码对 Python 2/3 均兼容 全自动安装:easy_install jieba 或者 pip in ...

  4. Windows+MyEclipse+MySQL【连接数据库报错caching_sha2_password】

    在MyEclipse中打开[窗口]->[显示视图]-> MyEclipse Database Browser -> (图片里倒三角)New.... ①Driver template: ...

  5. jdk1.8一键安装脚本(linux环境)

    1.下载jdk安装包和安装脚本 下载地址:https://pan.baidu.com/s/1bo6ADQ3 其中包括: jdk安装包:jdk-8u151-linux-x64.tar.gz jdk一键安 ...

  6. ajex 相关参数

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

  7. Scanner的概述与String类的构造和使用_DAY12

    1:Scanner的概述(理解) 1)Scanner是JDK5以后出现的方便我们从键盘接受数据的类. 2)Scanner的构造格式: Scanner sc = new Scanner(System.i ...

  8. (转)Python开发程序:支持多用户在线的FTP程序

    原文链接:http://www.itnose.net/detail/6642756.html 作业:开发一个支持多用户在线的FTP程序 要求: 用户加密认证 允许同时多用户登录 每个用户有自己的家目录 ...

  9. Java 多线程学习笔记:wait、notify、notifyAll的阻塞和恢复

    前言:昨天尝试用Java自行实现生产者消费者问题(Producer-Consumer Problem),在coding时,使用到了Condition的await和signalAll方法,然后顺便想起了 ...

  10. 18-hadoop-weather案例

    weather案例, 简单分析每年的前三个月的最高温即可, 使用自定义的分组和排序 设计分析 设定多个reduce 每年的数据都很多,如果按照默认情况处理,统计性能是非常慢(因为默认只有一个reduc ...