HDU4345————Permutation(置换群,dp)

本文探讨了在一个置换群中,不同置换关系下循环节长度的种类数量计算问题。通过数学转换,将问题转化为求解特定条件下最小公倍数的不同组合。

Permutation

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 910    Accepted Submission(s): 536


Problem Description
There is an arrangement of N numbers and a permutation relation that alter one arrangement into another.
For example, when N equals to 6 the arrangement is 123456 at first. The replacement relation is 312546 (indicate 1->2, 2->3, 3->1, 4->5, 5->4, 6->6, the relation is also an arrangement distinctly).
After the first permutation, the arrangement will be 312546. And then it will be 231456.
In this permutation relation (312546), the arrangement will be altered into the order 312546, 231456, 123546, 312456, 231546 and it will always go back to the beginning, so the length of the loop section of this permutation relation equals to 6.
Your task is to calculate how many kinds of the length of this loop section in any permutation relations.
 

Input
Input contains multiple test cases. In each test cases the input only contains one integer indicates N. For all test cases, N<=1000.
 

Output
For each test case, output only one integer indicates the amount the length of the loop section in any permutation relations.
 

Sample Input
  
1 2 3 10
 

Sample Output
  
1 2 3 16
 

Author
HIT
 

Source
 

Recommend
zhuyuanchen520
 


对于一个置换群,循环节的长度为独立置换环长度的最小公倍数。

这个问题问的是循环节的长度有多少种。

可以转化成和为N的数的最小公倍数有多少种。

因为1对最小公倍数没有影响,所以可以转化成和小于等于N的最小公倍数有多少种。





// test.cpp : 定义控制台应用程序的入口点。
//
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;

typedef long long ll;

const int MAXN = 1000 + 10;
const long long INF = 1000000000000000;
typedef long long ll;
int vis[MAXN] = { 0 };
int p[MAXN];
ll dp[MAXN], ans[MAXN];
int n;
int tot = 0;
void getprime() {
	for (int i = 2; i < MAXN; i++) {
		if (!vis[i]) {
			p[tot++] = i;
			for (int j = i * 2; j < MAXN; j += i) {
				vis[j] = 1;
			}
		}
	}
}
void init() {
	getprime();
	dp[0] = 1;
	for (int i = 0; i < tot; i++) {
		for (int j = MAXN-1; j ; j--) {
			for (int k = p[i]; k <= j; k *= p[i]) {
				dp[j] += dp[j - k];
			}
		}
	}
	ans[0] = 1;
	for (int i = 1; i <= 1000; i++)
		ans[i] = ans[i - 1] + dp[i];
}
int main() {
	init();
	while (cin >> n)
		cout << ans[n] << endl;
}








评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值