SGU 502 Digits Permutation
这个题目 正解应该是 dp 吧 对18个数字进行2进制枚举放不放,,,可以这么理解 以当前状态 stu,他对应的余数是 h 进入下一个状态; 进行记忆画搜索就行了
1 #include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstring>
#include<algorithm>
using namespace std; char str[]; bool vis[];
int dp[][],len; int res[];
int dfs( int stu,int h,int dep )
{
if( dep == len ){ if( h || str[res[]] == '' )return ;
for( int i = ; i < len; i++ )cout<<str[res[i]];cout<<endl;
return ;
}
if( dp[stu][h] == )return ;
for( int i = ; i < len; i++ )
if( !vis[i] ){
vis[i] = true;res[dep] = i;
int now = dfs( stu|(<<i),((h*)+(str[i]-''))%,dep+ );
vis[i] = false;
if( now == )return ;
}
return dp[stu][h] = ;
}
int main( )
{
while( scanf("%s",str) != EOF )
{
len = strlen( str );
memset( dp,-,sizeof(dp) );
memset( vis,,sizeof(vis) );
if( dfs( ,, ) == )cout<<"-1"<<endl;
}
return ;
}
SGU 502 Digits Permutation的更多相关文章
- ACM: SGU 101 Domino- 欧拉回路-并查集
sgu 101 - Domino Time Limit:250MS Memory Limit:4096KB 64bit IO Format:%I64d & %I64u Desc ...
- 【SGU 390】Tickets (数位DP)
Tickets Description Conductor is quite a boring profession, as all you have to do is just to sell ...
- LeetCode_Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...
- 【LeetCode】60. Permutation Sequence
题目: The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of t ...
- [Swift]LeetCode949. 给定数字能组成的最大时间 | Largest Time for Given Digits
Given an array of 4 digits, return the largest 24 hour time that can be made. The smallest 24 hour t ...
- CodeForces-915C Permute Digits
C. Permute Digits time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- LeetCode: Permutation Sequence 解题报告
Permutation Sequence https://oj.leetcode.com/problems/permutation-sequence/ The set [1,2,3,…,n] cont ...
- SGU 101 Domino (输出欧拉路径)
101. Domino time limit per test: 0.25 sec. memory limit per test: 4096 KB Dominoes – game played wit ...
- (水题)987654321 problem -- SGU 107
链接: http://vj.acmclub.cn/contest/view.action?cid=168#problem/G 时限:250MS 内存:4096KB 64位IO格式:%I ...
随机推荐
- redis 笔记01 简单动态字符串、链表、字典、跳跃表、整数集合、压缩列表
文中内容摘自<redis设计与实现> 简单动态字符串 1. Redis只会使用C字符串作为字面量,在大多数情况下,Redis使用SDS(Simple Dynamic String,简单动态 ...
- Cisco、HUAWEI、H3c、Firewall等设备配置snmp
配置HUAWEI交换机S1720.S2700.S5700.S6720等型号设备的snmp v3配置 注:此配置来源自官方配置文档 操作步骤 配置交换机的接口IP地址,使其和网管站之间路由可达 (图1) ...
- Linux系统下强大的lsof命令使用宝典
lsof命令简介: lsof(list open files)是一个列出当前系统打开文件的工具.在linux环境下,任何事物都以文件的形式存在,通过文件不仅仅可以访问常规数据,还可以访问网络连接和硬件 ...
- GRE/GMAT/LSAT长难句300例精讲精练-思维导图
<GRE/GMAT/LSAT长难句300例精讲精练>是GRE超人气名师陈琦老师团队的又一本新作,也是“再要你命3000”的新成员,从之前的词汇.短语.练习,提升到长难句层面,相信学完本书后 ...
- 《大型网站系统与JAVA中间件实践》读书笔记-数据访问层
数据访问层 5.1.2数据库垂直/水平拆分的困难 随着网站业务的快速发展,数据量和访问量不断上升,数据库的压力越来越大. 更换更好的硬件(Scale Up)是一种解决方案,而且在我们能付得起硬件费用并 ...
- 进程管理工具supervisor
1. 简介 supervisor有两个组件:supervisord和supervisorctl,组成了client/server结构. supervisord负责读入配置文件,然后supervisor ...
- Dispatcher initialization failedUnable to load configuration 解决办法
检查<package name="action" extends="struts-default"></package>中是否有exte ...
- ubuntu 支持中文
1.cat /usr/share/i18n/SUPPORTED 说明:查看系统支持的字符集,你需要注意的是支持字符集的格式,如对中文会有以下一些显示(我的系统如此,我不知是否普遍) zh_CN.GB1 ...
- TCP_AIO_Server_ZC_02
ZC: 这个例子是,1个skt 投递 N个未决的接收操作 (记得 以前查过 说 线程数是 CUP数量的2倍 比较合适) 1. // 当需要 投递多个接收操作的时候,可以将接收缓冲封装成类,然后再投递多 ...
- 如何进行数据库,比如ORACLE,SQL SERVER的逆向工程,将数据库导入到PowerDesigner中
Oracle的反向工程就是指将Oracle中的数据库,当然也可以是SQL Server中的数据库导入到PD中,这个需要建立一个数据库的链接,然后进行逆向工程的操作. 第一步:建立数据库的链接: Pow ...