解题思路:这题相当诡异,样例没过,交了,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. Leetcode: strStr()

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...

  2. Eclipse 字体选择

    Windows下推荐使用Consolas Linux下推荐使用DejaVu Sans Mono, Website: http://dejavu-fonts.org/wiki/Main_PageDown ...

  3. java 关于mysql

    com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after co ...

  4. ExtJs布局之accordion,fit,auto

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

  5. poj 1062(有限制的最短路)

    题目链接:http://poj.org/problem?id=1062 思路:要求对于最短路上的点,不能出现等级之差大于m,于是我们可以枚举,假设酋长的等级为level,于是这个区间范围[level- ...

  6. IDA 使用技巧

    我用的IDA Pro 6.5,把我自己使用ida的一些方法记录,免得自己遗忘 1 .导入符号表 可以像前一篇博客中写的那样,也可以使用File--->LoadFile--->PDB Fil ...

  7. Protobuf动态解析那些事儿

    需求背景 在接收到 protobuf 数据之后,如何自动创建具体的 Protobuf Message 对象,再做反序列化.“自动”的意思主要有两个方面:(1)当程序中新增一个 protobuf Mes ...

  8. DIV CSS设计时IE6、IE7、FF 与兼容性有关的特性(转载的)

    在网站设计的时候,应该注意css样式兼容不同浏览器问题,特别是对完全使用DIV CSS设计的网,就应该更注意IE6 IE7 FF对CSS样式的兼容,不然,你的网乱可能出去不想出现的效果! 所有浏览器 ...

  9. SSIS ->> Script Debugging and Troubleshooting

    Breakpoint是调试过程中最重要的手段,不仅对于Script Task和Script Component,对于任何其他的组件也是如此.可以在某个Event(如OnError)触发的时候设置断点来 ...

  10. 【流媒体】 Android 实时视频编码—H.264硬编码

    [流媒體] Android 实时视频编码—H.264硬编码 SkySeraph Apr 4th 2012 Email:skyseraph00@163.com 1  硬编码 & 软编码 硬编码: ...