poj 3590 The shuffle Problem(置换群的幂运算)
来源:互联网 发布:oppo专用root软件 编辑:程序博客网 时间:2024/06/06 00:26
Problem Link
poj 3590 The shuffle Problem
题目很简单,求一个
求
Analysis
对于一个置换来说,
所以对于
AC code
Source CodeProblem: 3590 User: taotaoMemory: 692K Time: 0MSLanguage: G++ Result: AcceptedSource Code#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<vector>using namespace std;typedef long long LL;const int maxn = 1111;int prime[110],primecnt;void sieve(){ memset(prime,1,sizeof(prime)); primecnt = 0; for(int i=2 ; i<=100 ; ++i) { if(prime[i]) { prime[primecnt++] =i; for(int j = i*i ; j<=100 ; j+=i) prime[j] = 0; } }}int step[100],maxlcm = 0;vector<int> ans;void dfs(int remain,int cur){ if(remain <prime[cur]) { int lcm = 1; for(int i = 0 ; i<cur ; ++i) if(step[i])lcm*=step[i]; if(maxlcm<lcm){ maxlcm = lcm; ans.clear(); for(int i=0 ; i<cur ; ++i) if(step[i])ans.push_back(step[i]); while(remain--)ans.push_back(1); } }else{ step[cur] = 0; if(cur+1<primecnt)dfs(remain,cur+1); for(step[cur] = prime[cur] ; step[cur]<=remain ; step[cur]*=prime[cur]) if(cur+1<primecnt)dfs(remain-step[cur],cur+1); }}int main(){ //freopen("H:\\c++\\file\\stdin.txt","r",stdin); //freopen("H:\\c++\\file\\stdout.txt","w",stdout); sieve(); int n; int T ;scanf("%d",&T); while(T--) { maxlcm = 0; memset(step,0,sizeof(step)); scanf("%d",&n); ans.clear(); dfs(n,0); printf("%d",maxlcm); sort(ans.begin(),ans.end()); int last = 0; for(int i=0 ; i<ans.size() ; ++i) { int k = ans[i]; int j = last+2; while(k>1) { printf(" %d",j);j++;k--; } printf(" %d",last+1); last +=ans[i]; //for(int i=0 ; i<ans.size() ; ++i)cout<<ans[i]<<" "; } printf("\n"); } return 0;}
0 0
- poj 3590 The shuffle Problem(置换群的幂运算)
- POJ 3590 The shuffle Problem 置换+DP
- poj 3590 The shuffle Problem (置换+分组背包)
- POJ 3590 The shuffle Problem(置换+DP)
- [POJ3590]The shuffle Problem(置换+dp)
- 【POJ 3590】The shuffle Problem
- poj 1721 CARDS(置换群的幂运算)
- POJ 1721-CARDS(置换群-单个循环置换幂运算 倒推)
- pku 3590 The shuffle Problem
- 置换群的整幂运算【置换群】
- 置换群幂运算
- 置换群幂运算
- pku1721 CARDS(置换群的幂运算) ???
- pku3128Leonardo's Notebook(置换群的幂运算) ???
- 置换群的幂运算总结
- poj 3128 Leonardo's Notebook(置换群的分数幂运算)
- pku3590 The shuffle Problem
- POJ3590 The shuffle Problem
- c语言(判断最大数)
- MongoDB基本操作
- 概率模型与计算机视觉
- 对运营越来越感兴趣
- 学习笔记之qt4程序中引入自定义窗口部件之单一继承方式
- poj 3590 The shuffle Problem(置换群的幂运算)
- 写框架思路进程(四)
- poj 1007 DNA Sorting(水)
- 将博客搬至CSDN
- 总结Unity 中[XXX]的用法
- gitosis库怎么转到gitlab
- html
- 数据结构实验之查找六:顺序查找
- POJ 3190 (贪心)