题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1015

这都能过……

 #include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; typedef long long ll;
const ll maxn = ;
ll aim;
ll n;
char str[maxn];
char ans[maxn];
char wtf[maxn];
bool flag; ll quickmul(ll x, ll n) {
ll ans = ;
ll t = x;
while(n) {
if(n & ) {
ans = (ans * t);
}
t = t * t;
n >>= ;
}
return ans;
} int main() {
// freopen("in", "r", stdin);
// freopen("out", "w", stdout);
while(~scanf("%I64d %s", &aim, str)) {
if(aim == && strcmp("END", str) == ) break;
memset(wtf, , sizeof(wtf));
n = strlen(str);
ll nn = << n;
flag = ;
sort(str, str+n, greater<char>());
for(ll i = ; i < nn; i++) {
ll cnt = ;
memset(ans, , sizeof(ans));
for(ll j = ; j < n; j++) {
if(( << j) & i) {
ans[cnt++] = str[j];
}
}
if(cnt != ) continue;
sort(ans, ans+cnt);
do {
ll tmp = ans[] - 'A' + ;
for(ll k = ; k < cnt; k++) {
tmp += quickmul(-, k) * quickmul(ans[k]-'A'+, k+);
}
if(tmp == aim) {
flag = ;
if(strcmp(wtf, ans) < ) {
strcpy(wtf, ans);
}
}
}while(next_permutation(ans, ans+cnt));
}
if(!flag) printf("no solution\n");
else printf("%s\n", wtf);
}
return ;
}

[HDOJ1015]Safecracker(DFS, 组合数学)的更多相关文章

  1. HDOJ-1015 Safecracker(DFS)

    http://acm.hdu.edu.cn/showproblem.php?pid=1015 题意:给出一个目标值target和一个由大写字母组成的字符串 A-Z分别对应权值1-26 要求从给出的字符 ...

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

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

  3. HDU 5379 Mahjong tree dfs+组合数学

    题意:给你一棵树来分配号码,要求是兄弟节点连续并且每一棵子树连续. 思路:因为要求兄弟和子树都是连续的,所以自己打下草稿就可以发现如果一个节点有3个或3个以上的非叶子结点,那么就无论如何也不能达到目的 ...

  4. 洛谷——P3914 染色计数

    P3914 染色计数 题目描述 有一颗NN个节点的树,节点用1,2,\cdots,N1,2,⋯,N编号.你要给它染色,使得相邻节点的颜色不同.有MM种颜色,用1,2,\cdots,M1,2,⋯,M编号 ...

  5. 组合数学(全排列)+DFS CSU 1563 Lexicography

    题目传送门 /* 题意:求第K个全排列 组合数学:首先,使用next_permutation 函数会超时,思路应该转变, 摘抄网上的解法如下: 假设第一位是a,不论a是什么数,axxxxxxxx一共有 ...

  6. HDU 1015 Safecracker【数值型DFS】

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

  7. hdu - 1010 Tempter of the Bone (dfs+奇偶性剪枝) && hdu-1015 Safecracker(简单搜索)

    http://acm.hdu.edu.cn/showproblem.php?pid=1010 这题就是问能不能在t时刻走到门口,不能用bfs的原因大概是可能不一定是最短路路径吧. 但是这题要过除了细心 ...

  8. HDU 1015 Safecracker (DFS)

    题意:给一个数字n(n<=12000000)和一个字符串s(s<=17),字符串的全是有大写字母组成,字母的大小按照字母表的顺序,比如(A=1,B=2,......Z=26),从该字符串中 ...

  9. hdu 1015(DFS)

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

随机推荐

  1. 【BZOJ】【1211】【HNOI2004】树的计数

    Prufer序列+组合数学 嗯哼~给定每个点的度数!求树的种数!那么很自然的就想到是用prufer序列啦~(不知道prufer序列的……自己再找找资料吧,这里就不放了,可以去做一下BZOJ1005明明 ...

  2. 【BZOJ】【1036】树的统计

    嗯这题是一道对树进行动态修改&查询的经典题目,可以拿来练习树链剖分~ 啊对于这种动态修改&查询的题目,我们最喜闻乐见的就是在一个序列上去做了,毕竟可以直接套各种数据结构模版啊,比如线段 ...

  3. phyreengine 3.12.0 安装遇到的问题

    发现他们文档都是旧的....略渣阿 需要安装vs2012 update4 vs2013update4 nvdia cg toolkits 3.1 以及 windows SDK 8.1 编译运行第一个s ...

  4. Build Simple HTTP server

    1. The server just support POST&PUT method 2. It is a Python server, and save upload files in sp ...

  5. LA 2031

    Mr. White, a fat man, now is crazy about a game named ``Dance, Dance, Revolution". But his danc ...

  6. POJ 2023 Choose Your Own Adventure(树形,dfs,简单题)

    题意: 输入一个整数n,表示有n组测试数据, 每组第一行输入一个整数x表示该组测试一共有x页,接下来输入x行,每行表示一页, 每页或者以C开头(第一页都是以C开头),或者以E开头,中间用引号括起一段文 ...

  7. iOS第三方地图-百度地图定位的封装

    // // BaiduMapTools.h // baidumapTest // // Created by apple on 15/8/26. // Copyright (c) 2015年 tqh. ...

  8. POJ 1455

    /* 冒泡排序n*(n-1)/2; */ #include <iostream> using namespace std; int main() { //freopen("acm ...

  9. 强大的grep命令

    1.作用 Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来.grep全称是Global Regular Expression Print,表示全 ...

  10. Good Bye 2015 A. New Year and Days 签到

    A. New Year and Days   Today is Wednesday, the third day of the week. What's more interesting is tha ...