这个题目 正解应该是  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 4292 Food (拆点最大流)

    题意:N个人,F种食物,D种饮料,给定每种食物和饮料的量.每个人有自己喜欢的食物和饮料,如果得到自己喜欢的食物和饮料才能得到满足.求最大满足的人数. 分析:如果只是简单地N个人选择F种食物的话可以用二 ...

  2. js小技巧(收集的)

    一.事件源对象 event.srcElement.tagName //IE浏览器 event.srcElement.type event.target.tagName //dom浏览器 event.t ...

  3. Javascript 小数保留2位

    1.字符串截取法 function get(){    var s = 22.127456 + "";    var str = s.substring(0,s.indexOf(& ...

  4. LVS原理详解以及部署

    linux virtual server简称LVS,Internet的快速增长使多媒体网络服务器面对的访问数量快速增加,服务器需要具备提供大量并发访问服务的能力,因此对于大负载的服务器来讲, CPU. ...

  5. JavaScript中堆栈解析,已经与delete之间的关系。

    1,在栈中的数据不会随意删除. 2,堆中的数据可以随意删除. 注意:用eval("var a")定义的变量存放在栈中. var 和function 语句在JavaScript中的优 ...

  6. jQuery多功能日历插件 带事件记录功能

    在线演示 本地下载

  7. jQuery垂直手风琴菜单 菜单项带小图标

    在线演示 本地下载

  8. jar包错误

    Exception in thread "main" java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger. ...

  9. jvm-内存区域与内存溢出异常

    内存区域与内存溢出异常 参考: http://www.cnblogs.com/ityouknow/p/5610232.html 所有的Java开发人员可能会遇到这样的困惑?我该为堆内存设置多大空间呢? ...

  10. Python学习(二)——深度学习入门介绍

    课程二:深度学习入门 讲师:David (数据分析工程师) 这门课主要介绍了很多神经网络的基本原理,非常非常基础的了解. 零.思维导图预览:                一.深度神经网络 1.神经元 ...