传送门


$1A$太爽了

从此$Candy?$完全理解了这种$DP$做法

和bzoj1025类似,不过是求最大的公倍数,并输出一个字典序最小的方案

依旧枚举质因子和次数,不足的划分成1

输出方案从循环长度小的到大的输出

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=;
typedef long long ll;
inline int read(){
char c=getchar();int x=,f=;
while(c<''||c>''){if(c=='-')f=-; c=getchar();}
while(c>=''&&c<=''){x=x*+c-''; c=getchar();}
return x*f;
}
int n,m;
int p[N];
bool notp[N];
void sieve(int n){
for(int i=;i<=n;i++){
if(!notp[i]) p[++m]=i;
for(int j=;j<=m&&i*p[j]<=n;j++){
notp[i*p[j]]=;
if(i%p[j]==) break;
}
}
}
int f[N][N],g[N][N];
int a[N],tot;
void getPath(int i,int j){
if(i==) return;
if(g[i][j]!=) a[++tot]=g[i][j];
getPath(i-,j-g[i][j]);
}
void dp(){
f[][]=;
for(int i=;i<=m;i++)
for(int j=;j<=n;j++){
f[i][j]=f[i-][j];
g[i][j]=;
for(int k=p[i];k<=j;k*=p[i])
if(f[i-][j-k]*k>f[i][j]){
f[i][j]=f[i-][j-k]*k;
g[i][j]=k;
}
}
int ans=,now=;
for(int i=;i<=n;i++) if(f[m][i]>f[m][ans]) ans=i;
printf("%d ",f[m][ans]);
for(;now<=n-ans;now++) printf("%d ",now);
//puts("totot");
tot=;
getPath(m,ans);
sort(a+,a++tot);
//for(int i=1;i<=tot;i++) printf("a %d %d\n",i,a[i]);
for(int i=;i<=tot;i++){
int _=now;
for(int j=;j<a[i];j++) printf("%d ",++now);
printf("%d ",_);
now++;
}
puts("");
}
int main(){
freopen("in","r",stdin);
sieve();
int T=read();
while(T--){
n=read();
dp();
}
}

POJ 3590 The shuffle Problem [置换群 DP]的更多相关文章

  1. poj 3590 The shuffle Problem——DP+置换

    题目:http://poj.org/problem?id=3590 bzoj 1025 的弱化版.大概一样的 dp . 输出方案的时候小的环靠前.不用担心 dp 时用 > 还是 >= 来转 ...

  2. POJ 3590 The shuffle Problem

    Any case of shuffling of n cards can be described with a permutation of 1 to n. Thus there are total ...

  3. poj 3590(dp 置换)

    题目的意思是对于序列1,2,...,n.要你给出一种字典序最小的置换使得经过X次后变成最初状态,且要求最小的X最大. 通过理解置换的性质,问题可以等价于求x1,x2,..,xn 使得x1+x2+... ...

  4. POJ - 1978 Hanafuda Shuffle

    最初给牌编号时,编号的顺序是从下到上:洗牌时,认牌的顺序是从上到下.注意使用循环是尽量统一“i”的初始化值,都为“0”或者都为“1”,限界条件统一使用“<”或者“<=”. POJ - 19 ...

  5. POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询)

    POJ.3468 A Simple Problem with Integers(线段树 区间更新 区间查询) 题意分析 注意一下懒惰标记,数据部分和更新时的数字都要是long long ,别的没什么大 ...

  6. POJ 3468.A Simple Problem with Integers-线段树(成段增减、区间查询求和)

    POJ 3468.A Simple Problem with Integers 这个题就是成段的增减以及区间查询求和操作. 代码: #include<iostream> #include& ...

  7. poj 3468 A Simple Problem with Integers 【线段树-成段更新】

    题目:id=3468" target="_blank">poj 3468 A Simple Problem with Integers 题意:给出n个数.两种操作 ...

  8. 线段树(成段更新) POJ 3468 A Simple Problem with Integers

    题目传送门 /* 线段树-成段更新:裸题,成段增减,区间求和 注意:开long long:) */ #include <cstdio> #include <iostream> ...

  9. POJ 1152 An Easy Problem! (取模运算性质)

    题目链接:POJ 1152 An Easy Problem! 题意:求一个N进制的数R.保证R能被(N-1)整除时最小的N. 第一反应是暴力.N的大小0到62.发现当中将N进制话成10进制时,数据会溢 ...

随机推荐

  1. c++(排序二叉树)

    前面我们讲过双向链表的数据结构.每一个循环节点有两个指针,一个指向前面一个节点,一个指向后继节点,这样所有的节点像一颗颗珍珠一样被一根线穿在了一起.然而今天我们讨论的数据结构却有一点不同,它有三个节点 ...

  2. MongoDB模拟多文档事务操作

    Mongodb不支持多文档原子性操作,因此依据两阶段提交协议(Two Phase Commits protocol)来模拟事务. 以两个银行账户之间的转账行为为例,来说明如何实现多文档间的事务操作. ...

  3. HDU 1562 Oil Deposits

    题目: The GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. G ...

  4. 安卓Acitivity的启动模式

    活动的四大启动模式 Ps:除了standar模式外,其他启动模式都要在AndroidManifest.xml中设置 android:lauchMode的值 安卓活动的启动模式(LaunchMode)有 ...

  5. SSM手把手整合教程&测试事务

    自打来了博客园就一直在看帖,学到了很多知识,打算开始记录的学习到的知识点 今天我来写个整合SpringMVC4 spring4 mybatis3&测试spring事务的教程,如果有误之处,还请 ...

  6. KEIL MDK 查看代码量、RAM使用情况--RO-data、RW-data、ZI-data

    KEIL RVMDK编译后的信息 Code是代码占用的空间, RO-data是 Read Only 只读常量的大小,如const型, RW-data是(Read Write) 初始化了的可读写变量的大 ...

  7. DEDECMS点击主栏目默认显示第一个子栏目列表的方法

    本文实例讲述了DEDECMS点击主栏目默认显示第一个子栏目列表的方法.分享给大家供大家参考.具体分析如下: 今天公司有个需求是,点击导航上的父栏目进去默认显示第一个子栏目的列表,以下是具体实现方法,可 ...

  8. JAVA WEB之Spring4.x JdbcTemplate

    jdbcTemplate 说白了,他就是Spring提供用于简化数据库访问的类 基本jdbc驱动访问数据库 /* 一个简易好用的数据库连接和访问类 */ package cslg.cn.control ...

  9. Spring学习之路一

    Spring 官网:http://projects.spring.io/spring-framework/ Spring下载地址:https://repo.spring.io/simple/libs- ...

  10. mybatis if条件查询 及<号的问题

    摘录自:http://flt95.blog.163.com/blog/static/12736128920136185841551/ <if test="p=='1'"> ...