您的位置:首页 > 其它

BZOJ1025[SCOI]游戏

2015-10-18 09:45 162 查看

1025: [SCOI2009]游戏

Time Limit: 1 Sec  Memory Limit: 162 MB
Submit: 1624  Solved: 1028

[Submit][Status][Discuss]

Description

windy学会了一种游戏。对于1到N这N个数字,都有唯一且不同的1到N的数字与之对应。最开始windy把数字按顺序1,2,3,……,N写一排在纸上。然后再在这一排下面写上它们对应的数字。然后又在新的一排下面写上它们对应的数字。如此反复,直到序列再次变为1,2,3,……,N。 如: 1 2 3 4 5 6 对应的关系为 1->2 2->3 3->1 4->5 5->4 6->6 windy的操作如下
1 2 3 4 5 6 2 3 1 5 4 6 3 1 2 4 5 6 1 2 3 5 4 6 2 3 1 4 5 6 3 1 2 5 4 6 1 2 3 4 5 6 这时,我们就有若干排1到N的排列,上例中有7排。现在windy想知道,对于所有可能的对应关系,有多少种可能的排数。

Input

包含一个整数,N。

Output

包含一个整数,可能的排数。

Sample Input

【输入样例一】

3

【输入样例二】

10

Sample Output

【输出样例一】

3

【输出样例二】

16

HINT

【数据规模和约定】

100%的数据,满足 1 <= N <= 1000 。

题解:

  即求和为n的所有可能组合的最小公倍数。

  考虑枚举质数,若组合出的书不达n,就补一,不影响答案。

 dp.

<span style="font-size:18px;">#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define ll long long
using namespace std;
bool mark[1005];
int p[1005],n;
ll ans=0,f[1005][1005];
int tot;
int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
void getprime()
{
for(int i=2;i<=1000;i++)
{
if(!mark[i])p[++tot]=i;
for(int j=1;j<=tot&&i*p[j]<=1000;j++)
{
mark[i*p[j]]=1;
if(i%p[j]==0)break;
}
}
}
void solve()
{
f[0][0]=1;
for(int i=1;i<=tot;i++)
{
for(int j=0;j<=n;j++)f[i][j]=f[i-1][j];
for(int j=p[i];j<=n;j*=p[i])
for(int k=0;k<=n-j;k++)
f[i][k+j]+=f[i-1][k];
}
for(int i=0;i<=n;i++)ans+=f[tot][i];
cout<<ans<<endl;
}
int main()
{
n=read();
getprime();
solve();
return 0;
}</span>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: