这个题目 正解应该是  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的更多相关文章

  1. ACM: SGU 101 Domino- 欧拉回路-并查集

    sgu 101 - Domino Time Limit:250MS     Memory Limit:4096KB     64bit IO Format:%I64d & %I64u Desc ...

  2. 【SGU 390】Tickets (数位DP)

    Tickets   Description Conductor is quite a boring profession, as all you have to do is just to sell ...

  3. LeetCode_Next Permutation

    Implement next permutation, which rearranges numbers into the lexicographically next greater permuta ...

  4. 【LeetCode】60. Permutation Sequence

    题目: The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of t ...

  5. [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 ...

  6. CodeForces-915C Permute Digits

    C. Permute Digits time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  7. LeetCode: Permutation Sequence 解题报告

    Permutation Sequence https://oj.leetcode.com/problems/permutation-sequence/ The set [1,2,3,…,n] cont ...

  8. SGU 101 Domino (输出欧拉路径)

    101. Domino time limit per test: 0.25 sec. memory limit per test: 4096 KB Dominoes – game played wit ...

  9. (水题)987654321 problem -- SGU 107

    链接: http://vj.acmclub.cn/contest/view.action?cid=168#problem/G 时限:250MS     内存:4096KB     64位IO格式:%I ...

随机推荐

  1. HDU 4370 - 0 or 1 (SPFA+思维)

    题意:给一个N*N的矩阵C,和一个N*N的只由0和1组成的矩阵X. X满足以下条件: 1.X 12+X 13+...X 1n=1  2.X 1n+X 2n+...X n-1n=1  3.任意 i (1 ...

  2. C#基础--应用程序域(Appdomain)

    AppDomain理解 为了保证代码的键壮性CLR希望不同服务功能的代码之间相互隔离,这种隔离可以通过创建多个进程来实现,但操作系统中创建进程是即耗时又耗费资源的一件事,所以在CLR中引入了AppDo ...

  3. 基于Promise对象的新一代Ajax API--fetch

    ***************************************************************** #fetch Request 使用isomorphic-fetch发 ...

  4. 去掉xml中的空格和换行符

    有时在拼接xml或是导入xml格式文件时,会无缘无故出现很多空格符合换行符,导致在转换json时会报各种错误,特此在网上找到了一中比较实用的方法: strxml = Regex.Replace(str ...

  5. Python 类的设计原则

    # 面向对象遵循的原则: SOLID # S(Single Responsibility Principle) # 单一职责原则 # 一个类只负责一项职责 # 好处 # 易于维护, 写出高内聚的代码 ...

  6. JAVA基础补漏--继承

    子类的对象在创建时,首先调用父类的构造函数,再调用子类自己的构造函数. 子类的构造函数中,有一个默认的super(),为一个无参调用,这个不显示,但会被首先调用,所有才会有父类构造函数被调用的情况. ...

  7. dedecms 织梦利用arcpagelist标签实现首页arclist分页

    DedeCMS首页arclist分页可以利用arcpagelist标签来实现,这里说一下调用方法:首先必须在首页的<head></head>标签里面引入如下js代码: < ...

  8. spark SQL学习(load和save操作)

    load操作:主要用于加载数据,创建出DataFrame save操作:主要用于将DataFrame中的数据保存到文件中 代码示例(默认为parquet数据源类型) package wujiadong ...

  9. Java 正则表达式 Pattern & Matcher

    通常会有这种需求: 在文档中搜索有规律的字符串,然后进行统计或者替换.Java.util.regex包下的Pattern和Matcher这两个类提供了通过正则表达式来匹配查询,甚至替换的功能.那么我们 ...

  10. 记一次Configured Capacity: 0 (0 B)的解决

    场景 最近hadoop集群新加了一个节点N,通过Ambari管理 一切正常. 过了两天发现,虽然集群每天要进几个G的数据(共8个节点),但节点N占用空间丝毫没有变化,显然没有进数据啊 日志 查看该节点 ...