解题思路:这题相当诡异,样例没过,交了,A了,呵呵,因为理论上是可以通过的,所以

     我交了一发,然后就神奇的过了。首先要看懂题目。

 #include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = ;
int vis[maxn], A[maxn], flag, len, sum, p[maxn], n;
char str[maxn]; int cmp(int x, int y)
{
return x > y;
} void DFS(int cnt)
{
if(cnt == )
{
sum = pow(p[], ) - pow(p[],) + pow(p[],) - pow(p[],) + pow(p[],);
if(sum == n) flag = ; //搜到符合条件的就跳出。
return ;
} for(int i = ; i < len; i++)
{
//每个点有选和不选两种情况,所以很自然想到回溯。
if(!vis[i])
{
p[cnt] = A[i];//存储路径
vis[i] = ;
DFS(cnt + );
vis[i] = ;
}
if(flag) return ; //这一步必不可少,表明搜到符合条件的就要立即跳出。
}
return ;
} int main()
{
while(~scanf("%d", &n))
{
memset(vis, , sizeof(vis));
scanf("%s", str);
if(strcmp(str, "END") == ) break;
len = strlen(str);
for(int i = ; i < len; i++) A[i] = str[i] - 'A' + ;
sort(A, A + len, cmp); //直接从大到下排序,搜到第一个符合条件的直接跳出。 flag = ;
DFS();
//flag等于1表示搜到了
if(flag) for(int i = ; i < ; i++) printf("%c", p[i] + );
else printf("no solution");
printf("\n");
}
return ;
}

HDU 1015 Safecracker的更多相关文章

  1. HDOJ(HDU).1015 Safecracker (DFS)

    HDOJ(HDU).1015 Safecracker [从零开始DFS(2)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1 ...

  2. hdu 1015 Safecracker 水题一枚

    题目链接:HDU - 1015 === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Klein s ...

  3. ZOJ 1403&&HDU 1015 Safecracker【暴力】

    Safecracker Time Limit: 2 Seconds      Memory Limit: 65536 KB === Op tech briefing, 2002/11/02 06:42 ...

  4. HDU 1015 Safecracker【数值型DFS】

    Safecracker Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  5. HDU 1015 Safecracker(第一次用了搜索去遍历超时,第二次用for循环能够了,思路一样的)

    Safecracker Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total S ...

  6. HDU 1015.Safecracker【暴力枚举】【8月17】

    Safecracker Problem Description === Op tech briefing, 2002/11/02 06:42 CST ===  "The item is lo ...

  7. HDOJ/HDU 1015 Safecracker(深搜)

    Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Kle ...

  8. HDOJ/HDU 1015 Safecracker(枚举、暴力)

    Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Kle ...

  9. HDU 1015 Safecracker 解决问题的方法

    Problem Description === Op tech briefing, 2002/11/02 06:42 CST ===  "The item is locked in a Kl ...

随机推荐

  1. 2014多校第三场1005 || HDU 4891 The Great Pan(模拟)

    题目链接 题意 : 给你n行字符串,问你有多少种理解方式.有两大类的理解 (1){A|B|C|D|...}代表着理解方式可以是A,可以是B或C或者D. (2)$blah blah$,在$$这两个符号中 ...

  2. ExtJs之Ext.util.CSS

    <!DOCTYPE html> <html> <head> <title>ExtJs</title> <meta http-equiv ...

  3. HBase保存的各个字段意义解释

    /×××××××××××××××××××××××××××××××××××××××××/ Author:xxx0624 HomePage:http://www.cnblogs.com/xxx0624/ ...

  4. 初学Ajax(二)

    $.get()和$.post() .load()方法是局部方法,因为它需要一个包含元素的jQuery对象作为前缀.而$.get()和$.post()是全局方法,无须指定某个元素.对于用途而言,.loa ...

  5. 妙味课堂——HTML+CSS(第四课)(一)

    这一课学的东西真是太多了,还不赶快记下来,留待以后慢慢回味! 首先我们回顾一下inline-block的特性: 使块元素在一行显示 使内嵌支持宽高 换行被解析了(问题) 不设置宽度的时候,宽度由内容撑 ...

  6. pycharm控制台中文乱码问题

    pycharm控制台中文乱码问题一般是因为之前有配置保存到了文件里, C盘下.pycharm文件夹下有配置文件,删除文件后重装pycharm,配置会重置 不过最后解决问题的做法是删除配置文件后,重新装 ...

  7. C语言,一个彩票摇奖程序摇出22选5的中奖号码

    摇奖机摇奖,无非就是利用它的随机性,让球从摇奖机中随机地掉出,就成了中奖号码.而C语言中也同样有个rand()函数可以产生随机数,利用这个rand()函数产生的随机数,同样可以代替从摇奖机中随机摇出的 ...

  8. Delphi是座宝山,有待挖掘

    Delphi是座宝山,有待挖掘1. VCL源码是座宝山,把纷繁复杂的Windows编程封装到短短几个类里,不超过8000行代码,还额外包括许多其它的技巧2. RTL是座宝山,方便程序员使用底层运算,不 ...

  9. 297. Serialize and Deserialize Binary Tree

    题目: Serialization is the process of converting a data structure or object into a sequence of bits so ...

  10. Getting Started with Mongoose and Node.js – A Sample Comments System | Dev Notes

    In this post, we’re going to be creating a sample comments system using Node, Express and Mongoose.  ...