https://codeforces.com/problemset/problem/65/D

哈利波特!一种新思路的状压记忆化dfs,记得每次dfs用完要减回去。而且一定是要在dfs外部进行加减!防止在中间return的时候忘记弄回来。用哈希记录状态实现真正的记忆化。

#include<bits/stdc++.h>
using namespace std;
#define ll long long int n;
char s[]; ll getID(int a[]){
ll res=;
for(int i=;i<;i++){
res=res*+a[i];
}
return res;
} int a[]={};
int c[]={}; set<ll> se; int dfs(int i){
ll ID=getID(a);
if(se.count(ID))
return ;
else{
se.insert(ID);
//printf("%d-%lld\n",i,ID);
if(i==n){
int minnum=*min_element(a,a+);
for(int j=;j<;j++){
if(a[j]==minnum){
c[j]=;
}
}
return ;
}
} if(s[i]!='?'){
switch (s[i]){
case 'G':
a[]++;
dfs(i+);
a[]--;
break;
case 'H':
a[]++;
dfs(i+);
a[]--;
break;
case 'R':
a[]++;
dfs(i+);
a[]--;
break;
case 'S':
a[]++;
dfs(i+);
a[]--;
}
}
else{
int minnum=*min_element(a,a+);
for(int j=;j<;j++){
if(a[j]==minnum){
//cout<<"j="<<j<<endl;
a[j]++;
dfs(i+);
a[j]--;
}
}
}
} int main(){
scanf("%d",&n);
scanf("%s",s);
dfs(); //printf("%d\n",se.size()); if(c[])
puts("Gryffindor");
if(c[])
puts("Hufflepuff");
if(c[])
puts("Ravenclaw");
if(c[])
puts("Slytherin"); }

Codeforces - 65D - Harry Potter and the Sorting Hat - 简单搜索的更多相关文章

  1. Timus 1446. Sorting Hat 分类问题

    At the start of each school year, a very important event happens at Hogwarts. Each of the first-year ...

  2. Codeforces Round #335 (Div. 2) C. Sorting Railway Cars 动态规划

    C. Sorting Railway Cars Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/conte ...

  3. Codeforces Round #335 (Div. 2) C. Sorting Railway Cars 连续LIS

    C. Sorting Railway Cars   An infinitely long railway has a train consisting of n cars, numbered from ...

  4. Codeforces 258D Little Elephant and Broken Sorting (看题解) 概率dp

    Little Elephant and Broken Sorting 怎么感觉这个状态好难想到啊.. dp[ i ][ j ]表示第 i 个数字比第 j 个数字大的概率.转移好像比较显然. #incl ...

  5. Codeforces Round #335 (Div. 2) C. Sorting Railway Cars

    C. Sorting Railway Cars time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  6. CodeForces - 258D Little Elephant and Broken Sorting

    Discription The Little Elephant loves permutations of integers from 1 to n very much. But most of al ...

  7. CodeForces 258D Little Elephant and Broken Sorting(期望)

    CF258D Little Elephant and Broken Sorting 题意 题意翻译 有一个\(1\sim n\)的排列,会进行\(m\)次操作,操作为交换\(a,b\).每次操作都有\ ...

  8. Codeforces Round #424 Div2 E. Cards Sorting

    我只能说真的看不懂题解的做法 我的做法就是线段树维护,毕竟每个数的顺序不变嘛 那么单点维护 区间剩余卡片和最小值 每次知道最小值之后,怎么知道需要修改的位置呢 直接从每种数维护的set找到现在需要修改 ...

  9. Codeforces Round #336 (Div. 2) D. Zuma 记忆化搜索

    D. Zuma 题目连接: http://www.codeforces.com/contest/608/problem/D Description Genos recently installed t ...

随机推荐

  1. PS 魔法棒

    魔术棒工具是通过选取图像中颜色相近或大面积单色区域的像素来制作选区,魔术棒用于纯色背景中较多. 容差数值越大,选择出的选区就越大,容差越小,对颜色差别的要求也就越严格,选择出的选区也就越小 按住shi ...

  2. 2017-07-19-CR 和 LF

    CR 和 LF CR - Carriage Return 回车 LF - Line Feed 换行 Carriage 打字机滑轨.老式打字机,打字时,滑轨从左往右移动,一行打完了,需要把滑轨调回到最左 ...

  3. iOS开发---- 开发错误汇总及解决方法

    本文转载至 http://blog.csdn.net/shenjx1225/article/details/8561695 一.今天调试程序的时候,出现了一个崩溃,信息如下: 2013-02-01 0 ...

  4. 九度OJ 1095:2的幂次方 (递归)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:913 解决:626 题目描述: Every positive number can be presented by the exponent ...

  5. Windows消息、绘图与多线程

    有一个项目,一旦点下按钮后,用死循环不停的读数据,读出后立刻用可视化的方法显示.如果不采用多线程的方法,程序运行都正确,但无法关闭窗口,不清楚是窗口无法通过关闭按钮来接受Windows消息,还是接受了 ...

  6. zoom:1

    zoom这个特性是IE特有的属性.   zoom:1;一般是拿来解决IE6的子元素浮动时候父元素不随着自动扩大的问题,功能相当于overflow:auto,同样也可以用height:1%来代替zoom ...

  7. mysql学习笔记(七)—— MySQL内连接和外连接

        MySQL内连接(inner join on) MySQL的内连接使用inner join on,它的效果跟使用where是一样的,如果联结的是两个表,那么需要左右的条件或者说字段是需要完全匹 ...

  8. php-循环普通数组和关联数组

    <?php //循环普通数组 $arr=array("杭州","成都","拉萨"); $arrlength=count($arr); ...

  9. ORA-32001:write to SPFILE requested but no SPFILE is in use

    oracle报错: ORA-32001:write to SPFILE requested but no SPFILE is in use 解决方法: 1.查看是否有spfile sql> sh ...

  10. 201621123007 Java程序设计第一周 学习总结

    第一周-Java基本概念 201621123007 <Java程序设计> 第一周学习总结 1. 本周学习总结 java是面向对象的一类语言,三大特征:封装性,继承性,多态性. jdk jr ...