Codeforces - 65D - Harry Potter and the Sorting Hat - 简单搜索
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 - 简单搜索的更多相关文章
- Timus 1446. Sorting Hat 分类问题
At the start of each school year, a very important event happens at Hogwarts. Each of the first-year ...
- 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 ...
- 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 ...
- Codeforces 258D Little Elephant and Broken Sorting (看题解) 概率dp
Little Elephant and Broken Sorting 怎么感觉这个状态好难想到啊.. dp[ i ][ j ]表示第 i 个数字比第 j 个数字大的概率.转移好像比较显然. #incl ...
- 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 ...
- 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 ...
- CodeForces 258D Little Elephant and Broken Sorting(期望)
CF258D Little Elephant and Broken Sorting 题意 题意翻译 有一个\(1\sim n\)的排列,会进行\(m\)次操作,操作为交换\(a,b\).每次操作都有\ ...
- Codeforces Round #424 Div2 E. Cards Sorting
我只能说真的看不懂题解的做法 我的做法就是线段树维护,毕竟每个数的顺序不变嘛 那么单点维护 区间剩余卡片和最小值 每次知道最小值之后,怎么知道需要修改的位置呢 直接从每种数维护的set找到现在需要修改 ...
- Codeforces Round #336 (Div. 2) D. Zuma 记忆化搜索
D. Zuma 题目连接: http://www.codeforces.com/contest/608/problem/D Description Genos recently installed t ...
随机推荐
- jQuery UI Autocomplete是jQuery UI的自动完成组件
支持的数据源 jQuery UI Autocomplete主要支持字符串Array.JSON两种数据格式. 普通的Array格式没有什么特殊的,如下: ? 1 ["cnblogs" ...
- Webkit一:Dom转码和解析
因为真正的数据的处理是由DocumentParser::appendBytes以及DocumentParser::finish后续调用来完成,所以咱们重点关注这两块 数据接收和解码 TextResou ...
- Python 元祖、列表、字典、文件(转载)
转自http://yangsq.iteye.com/category/20857 python的元组.列表.字典数据类型是很python(there python is a adjective)的数据 ...
- 多媒体开发之--- Live555 server 获取不到本地ip 全为0
今天把wis-streamer live555 移植到8148上面跑起来了,运行testOnDemandRTSPServer的时候发现,本地IP地址居然为0.0.0.0; 于是乎就跟踪调试了下,看看它 ...
- 继续聊WPF——获取ComboBox中绑定的值
千万不要认为WPF中的数据绑定会很复杂,尽管它的确比Winform程序灵活多了,但其本质是不变的,特别是ComboBox控件,我们知道在Winform中对该控件的有两个专为数据绑定而设定的属性——Di ...
- hdu5261单调队列
题意特难懂,我看了好多遍,最后还是看讨论版里别人的问答,才搞明白题意,真是汗. 其实题目等价于给n个点,这n个点均匀分布在一个圆上(知道圆半径),点与点之间的路程(弧长)已知,点是有权值的,已知,点与 ...
- JQery 动态填充数据到table 中
说明: 1.把数据库中的数据查询出来,填充到前台的table中,注意 从数据查询出来的 属性IsNew="0"(table 行tr的属性) 2.单击“添加”按钮 新添加行追加到ta ...
- memcmp和strcmp的返回值
注意,无论是内存比较还是字符串比较,这两个函数的返回值的意义是一样的. 如果相同,返回0 如果前面大于后面,返回大于0 如果前面小于后面,返回小于0 一定要注意,相同的时候是0,不是true.
- vim学习之以退为进——可反复移动和可反复改动的美妙结合
时间:2014.06.29 地点:基地 -------------------------------------------------------------------------------- ...
- 模拟等待事件:db file sequential read
相关知识: db file sequential read 单块读 optimizer_index_cost_adj 这个初始化参数代表一个百分比,取值范围在1到10000之间.该参数表示索引扫描和 ...