这个题目 正解应该是  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. 记录一次代码错误,elastic search的INDEX需要使用小写字母

    Caused by: org.elasticsearch.hadoop.EsHadoopIllegalArgumentException: Cannot determine write shards ...

  2. 使用阿里的maven库

    快使用阿里云的maven仓库 自从开源中国的maven仓库挂了之后就一直在用国外的仓库,慢得想要砸电脑的心都有了.如果你和我一样受够了国外maven仓库的龟速下载?快试试阿里云提供的maven仓库,从 ...

  3. 外部类与main方法笔记

    外部类 1. 外部public class只能有一个 2. 外部类只能有两种访问控制级别: public 和默认 3. 一个文件中,可以有多个public class,即外部类为public,还可以有 ...

  4. viewport大白话

    以下所有内容均是我自己理解的,可能有误,懂得大佬希望指点一下我.. 首先,写一个简单的页面.里面只有1个200*200的div <html lang="en"> < ...

  5. React-Native 常用组件学习资料链接

    以下链接是自己开发RN工程时参考的一些不错的资料,给喜欢学习的朋友分享以下. React-Native组件用法详解之ListViewhttp://www.jianshu.com/p/1293bb8ac ...

  6. COS-8文件系统

    操作系统(Operating System,简称OS)是管理和控制计算机硬件与软件资源的计算机程序,是直接运行在“裸机”上的最基本的系统软件,任何其他软件都必须在操作系统的支持下才能运行.   操作系 ...

  7. JAVA基础补漏--内部类

    成员内部类 public class InnerClass { public static void main(String[] args) { System.out.println("++ ...

  8. powerdesigner 左边的列表框弄不见了怎么弄出来

    快捷键  Alt + 0(数字零)  或者点击下面图片的 红色标识位置.就出来了.

  9. windchill系统——开发_客户端自定义

    步骤如下

  10. merge two sorted lists, 合并两个有序序列

    /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * Lis ...