传送门


$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. 拿到List<Map<String,String>>对用属性的值。。。。。。。

    list.get(i).get("orderNumber") 来拿到下面的对应属性的值

  2. Caused by: java.sql.SQLException: Couldn't perform the operation getAutoCommit: You can't perform any operations on this connection. It has been automatically closed by Proxool for some reason (see lo

    系统启动,一段时间不操作,然后在来操作时,报错如下: Caused by: java.sql.SQLException: Couldn't perform the operation getAutoC ...

  3. Vue2反向代理

      前一段时间写了一个vue2的小项目,用的是vue-cli脚手架搭建的项目,项目里需要跨域,但又不能使用jsonp,上网查了一下,发现有一个之前没接触过的词语--反向代理. 什么是"反向代 ...

  4. myeclipse中git的使用

    1.右键项目,team-->commit,勾选修改了的文件,点击commit(将更新提交到本地仓库)2.右键项目,team-->pull,合并本地仓库和远程服务器仓库,pull后有一些文件 ...

  5. tp路由+伪静态+去掉index.php

    浏览:10536 发布日期:2013/10/08 分类:技术分享 关键字: 路由 伪静态 去掉index.php 之前一个网友说能不能达到这样的效果,www.olcms.com/news/id.htm ...

  6. Angular 4+ Http

    HTTP: 使应用能够对远端服务器发起相应的Http调用: 你要知道: HttpModule并不是Angular的核心模块,它是Angualr用来进行Web访问的一种可选方式,并位于一个名叫@angu ...

  7. 堡垒机之paramiko模块

    一.paramiko简单介绍 场景预设: 很多运维人员平时进行维护linux/unix主机时候,无非通过ssh到相应主机操作,那么一旦主机有成千上百台,那该如何应对,这时候我们需要批处理工具,基于py ...

  8. 静态html制作之psd转html

    很多时候我们开发拿到的是psd文件,这个时候如果公司有前端,会帮你制作成静态html, 很多小公司是没有这个配置的,所以只能业务开发的自己上马.可以有多种实现方式: 1.对于简单的切图,可以在线网站切 ...

  9. 未找到约束ContractName Microsoft.VisualStudio.Text.ITextDocumentFactoryServiceRequiredTypeIdentity匹配的导出的解决办法

    未找到约束ContractName Microsoft.VisualStudio.Text.ITextDocumentFactoryServiceRequiredTypeIdentity Micros ...

  10. U8g2库I2C总线再次突破性调试成功

    这次采用U8X8的方式,不再采用u8g2,因为后者一直报内存问题.所以采用了不占内存的u8x8模式 同时u8g2库文件的示例代码也是很牛逼的, 里面还有message box 非常的可爱运行效果也非常 ...