BZOJ 1306 DFS
思路:
搜索就好
(注意不要枚举太多东西)
//By SiriusRen
#include <cstdio>
using namespace std;
int n,point[10],ans[10][10],answer;
bool check(){
for(int i=1;i<=n;i++)
if(point[i])return 0;
return 1;
}
void dfs(int x,int y){
if(x>n||y>n){
if(check())answer++;
return;
}
if(point[x]>(n-y+1)*3)return;
if(y==n){
if(point[x]==1){
point[x]--,point[y]--;
dfs(x+1,x+2);
point[x]++,point[y]++;
}
else if(point[x]==3){
point[x]-=3;
dfs(x+1,x+2);
point[x]+=3;
}
else if(!point[x]){
point[y]-=3;
dfs(x+1,x+2);
point[y]+=3;
}
}
else
{
if(point[x]-1>=0&&point[y]-1>=0){
point[x]-=1,point[y]-=1;
dfs(x,y+1);
point[x]+=1,point[y]+=1;
}
if(point[x]-3>=0&&point[y]>=0){
point[x]-=3;
dfs(x,y+1);
point[x]+=3;
}
if(point[y]-3>=0&&point[x]>=0){
point[y]-=3;
dfs(x,y+1);
point[y]+=3;
}
}
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&point[i]);
dfs(1,2);
printf("%d\n",answer);
}
BZOJ 1306 DFS的更多相关文章
- bzoj 1306: [CQOI2009]match循环赛【dfs+剪枝】
大力剪枝,最后洛谷上还开了o2才过-- 大概这样剪枝: 1.搜索中,一个队当前得分超过要求或者一个队剩下的比赛场数全赢也达不到要求则return: 2.注意到如果平局,最总分的贡献是2,否则是3,所以 ...
- bzoj 4034(DFS序+线段树)
这个题多了一个操作难度直线上升,看完题解才会写 有一棵点数为 N 的树,以点 1 为根,且树点有边权.然后有 M 个操作,分为三种:操作 1 :把某个节点 x 的点权增加 a .操作 2 :把某个节点 ...
- bzoj 2819(DFS序+树状数组+博弈+lca)
2819: Nim Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 2045 Solved: 795[Submit][Status][Discuss] ...
- bzoj 1225 dfs + 一点点数论
思路:有一个公式 如果 x = a1 ^ b1 * a2 ^ b2 * ...... * an ^ bn 其中ai为质数,那么总共的因子个数为 (b1 + 1) * (b2 + 1) *....* ...
- bzoj 2440 dfs序
首先我们可以做一遍dfs,用一个队列记录每个点进出的顺序,当每个点访问的时候que[tot++]=x,记为in[x],当结束dfs的时候que[tot++]=x,记为out[x],这样处理出来的队列, ...
- [USACO08OPEN]农场周围的道路Roads Around The Farm BZOJ 1621 DFS
Farmer John's cows have taken an interest in exploring the territory around the farm. Initially, all ...
- bzoj 2435 dfs处理
Description 在 W 星球上有 n 个国家.为了各自国家的经济发展,他们决定在各个国家 之间建设双向道路使得国家之间连通.但是每个国家的国王都很吝啬,他们只愿 意修建恰好 n – 1条双向道 ...
- BZOJ 3522 DFS+DP
思路: f[]表示选1个点的 g[]表示选2个点的 dp一下 ans+=(ll)g[k]*deep[k]; g[k]+=(ll)f[k]*deep[k]; f[k]+=deep[k]; 听说有O(n) ...
- BZOJ 2819 DFS序+线段树
非递归的DFS写炸了- 交了一个递归版的 过了---.. //By SiriusRen #include <cstdio> #include <cstring> #includ ...
随机推荐
- mariadb数据库的链接查询和表格设计
链接查询 练习准备: --创建学生表 create table students ( id int unsigned not null auto_increment primary key, name ...
- 紫书 习题 11-16 UVa 1669(树形dp)
想了很久, 以为是网络流最大流, 后来建模建不出来, 无奈. 后来看了 https://blog.csdn.net/hao_zong_yin/article/details/79441180 感觉思路 ...
- vjudge A - Beautiful numbers
A - Beautiful numbers Volodya is an odd boy and his taste is strange as well. It seems to him that a ...
- Qt之OpenSSL
简述 OpenSSL是一个强大的安全套接字层密码库,囊括主要的密码算法.常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用. 简述 下载安装 使用 更多参考 下载安装 ...
- 在独立的文件里定义WPF资源
一.文章概述 本演示介绍怎样在单独的文件里定义WPF资源.并在须要的地方调用相关资源文件. 相关下载(代码.屏幕录像):http://pan.baidu.com/s/1sjO7StB 在线播放:htt ...
- 利用艺术家的整数ID映射将标签转换为向量
<strong><span style="font-size:18px;">/*** * @author YangXin * @info Mapper选择艺 ...
- android openGL ES2 一切从绘制纹理開始
纹理.在openGL中,能够理解为载入到显卡显存中的图片.Android设备在2.2開始支持openGL ES2.0.从前都是ES1.0 和 ES1.1的版本号.简单来说,openGL ES是为了嵌入 ...
- 10.29 工作笔记 ndk编译C++,提示找不到头文件(ndk-build error: string: No such file or directory)
ndk编译C++.提示找不到头文件(ndk-build error: string: No such file or directory) 被这个问题弄得愁眉苦脸啊.心想为啥一个string都找不到呢 ...
- 51nod-1131: 覆盖数字的数量
[传送门:51nod-1131] 简要题意: 给出A,B,表示有一个区间为A到B 给出X,Y,表示有一个区间为X到Y 求出X到Y中能够被A到B中的数(可重复)相加得到的不同的数的个数 题解: 乱搞题, ...
- Word histogram
Here is a program that reads a file and builds a histogram of the words in the file: process_file lo ...