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. [转]据说200G网盘资料

    来源:HACK学习呀 2015cracer入侵入门到精通视频教程 点我查看 trf3 一笔√带过入侵教程 点我查看 ypan [复仇者]新手入门系列(7套) 点我查看 g1tb 菜鸟入门,做的确实不错 ...

  2. 百度小程序button去掉默认边框

    百度小程序button去掉默认边框: button::after{ border:none; }

  3. 文本属性和字体属性,超链接导航栏案例 background

    文本属性 介绍几个常用的. 文本对齐 text-align 属性规定元素中的文本的水平对齐方式. 属性值:none | center | left | right | justify 文本颜色 col ...

  4. cisco 的ACL

    搞网络好几年了,怎么说呢,水平一直停留在NA-NP之间,系统的学完NA后,做了不少实验,后来也维护了企业的网络,各种网络设备都玩过(在商汤用的Juniper srx 550 我认为在企业环境,非IDC ...

  5. Doxygen的使用,配置及实例

    Doxygen是一种开源跨平台的,以类似JavaDoc风格描述的文档系统,可以从一套归档源文件开始,生成文档 下载Doxygen + Graphviz Doxygen可以生成动态文档 Graphviz ...

  6. linux源码安装的步骤

    源码安装的过程中多多少少会遇到问题,在此仅简述一下安装的步骤,具体安装的过程中遇到的问题,具体解决. 安装步骤: 1.获取源码 name.gz 2.解包 tar -xvf name.gz (cd到包解 ...

  7. iOS开发手记-iOS8中使用定位服务解决方案

    问题描述: 在iOS8之前,app第一次开始定位服务时,系统会弹出一个提示框来让用户选择是否允许使用定位信息.但iOS8后,app将不会出现这个弹窗.第一次运行之后,在设置->隐私->定位 ...

  8. 开发创建XMPP“发布订阅”扩展(xmpp pubsub extend)

    发布订阅(PubSub)是一个功能强大的XMPP协议扩展.用户订阅一个项目(在xmpp中叫做node),得到通知时,也即当事项节点更新时.xmpp服务器通知用户(通过message格式). 节点类型: ...

  9. Strom的trident小例子

    上代码: public class TridentFunc { /** * 类似于普通的bolt */ public static class MyFunction extends BaseFunct ...

  10. 一口一口吃掉Hexo(四)

    如果你想得到更好的阅读效果,请访问我的个人网站 ,版权所有,未经许可不得转载! 人总是不会满足于现状,接下来我们就可以让我们的朋友们通过独立域名访问我们的网站了,但是这肯定是要花点钱的,所以这篇文章难 ...