这个题目 正解应该是  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. SVN插件下载地址及更新地址

    SVN插件下载地址及更新地址,你根据需要选择你需要的版本.现在最新是1.8.xLinks for 1.8.x Release:Eclipse update site URL: http://subcl ...

  2. $微信小程序开发实践点滴——Bmob常用API的使用

    Bmob后端云官网:http://www.bmob.cn/ Bmob后端云微信小程序开发文档:http://docs.bmob.cn/data/wechatApp/b_developdoc/doc/i ...

  3. vue项目 dev正常 build发生错误

    提取错误信息: 这个文件有错误,检查并修改即可 经过排除检查错误地方如下:多了个逗号

  4. SSL证书是“盾牌“还是”鸡肋“?

    德国联邦安全与IT办公室(BSI,职能相当于美国的国家安全与信息技术局)近日发布公告警告:网络攻击者冒充其发布了“关于Meltdown与Spectre攻击信息”的垃圾邮件,该邮件中包含指向修复补丁的页 ...

  5. I方法怎么不能获取多选框的数据

    前端代码 <input type="checkbox" name="m_name" value="{$vo.name}" class ...

  6. Android -- 读写文件到内部ROM,SD卡,SharedPreferences,文件读写权限

    (内容整理自张泽华教程) 1. 概述 使用文件进行数据存储 首先给大家介绍使用文件如何对数据进行存储,Activity提供了openFileOutput()方法可以用于把数据输出到文件中,具体的实现过 ...

  7. 抓jsoup_02_数据

    1.测试网页:http://ajax.mianbao99.com/vod-showlist-id-8-order-time-c-3719-p-1.html ZC: 直接查看的话,使用这个链接:http ...

  8. 2017版:KVM 性能优化之内存优化

    我们说完CPU方面的优化,接着我们继续第二块内容,也就是内存方面的优化.内存方面有以下四个方向去着手: EPT 技术 大页和透明大页 KSM 技术 内存限制 1. EPT技术 EPT也就是扩展页表,这 ...

  9. Spark- 根据ip地址计算归属地

    主要考察的是广播变量的使用: 1.将要广播的数据 IP 规则数据存放在HDFS上,(广播出去的内容一旦广播出去产就不能改变了,如果需要实时改变的规则,可以将规则放到Redis中) 2.在Spark中转 ...

  10. LeetCode第[33]题(Java):Search in Rotated Sorted Array

    题目:在翻转有序中搜索 难度:Medium 题目内容: Suppose an array sorted in ascending order is rotated at some pivot unkn ...