USACO Section 2.2: Party Lamps
这题有个小技巧, 按一个键两次等于没按,所以如果depsum > 16的话其实不用做深搜到depsum次,而只要16次就可以了。
/*
ID: yingzho1
LANG: C++
TASK: lamps
*/
#include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <algorithm>
#include <stdio.h>
#include <queue>
#include <cstring>
using namespace std;
ifstream fin("lamps.in");
ofstream fout("lamps.out");
int N, depsum;
bool check(string s, vector<int> &on, vector<int> &off) {
; i < on.size(); i++) {
') return false;
}
; i < off.size(); i++) {
') return false;
}
return s.size();
}
void dfs(set<string> &res, int c1, int c2, int c3, int c4, string s, vector<int> &on, vector<int> &off, int dep) {
if (check(s, on, off)) {
== ) {
res.insert(s);
//return;
}
}
|| dep > depsum) return;
string pre = s;
) {
dfs(res, c1+, c2, c3, c4, s, on, off, dep+);
; i < s.size(); i++) {
';
';
}
dfs(res, c1+, c2, c3, c4, s, on, off, dep+);
}
s = pre;
) {
dfs(res, c1, c2+, c3, c4, s, on, off, dep+);
; i < s.size(); i++) {
== ) {
';
';
}
}
dfs(res, c1, c2+, c3, c4, s, on, off, dep+);
}
s = pre;
) {
dfs(res, c1, c2, c3+, c4, s, on, off, dep+);
; i < s.size(); i++) {
== ) {
';
';
}
}
dfs(res, c1, c2, c3+, c4, s, on, off, dep+);
}
s = pre;
) {
dfs(res, c1, c2, c3, c4+, s, on, off, dep+);
; i < s.size(); i++) {
== ) {
';
';
}
}
dfs(res, c1, c2, c3, c4+, s, on, off, dep+);
}
s = pre;
}
int main()
{
fin >> N >> depsum;
');
int n;
vector<int> on, off;
//cout << N << " " << depsum << endl;
) on.push_back(n-);
) off.push_back(n-);
//for (int i = 0; i < on.size(); i++) cout << on[i] << endl;
//for (int i = 0; i < off.size(); i++) cout << off[i] << endl;
set<string> res;
dfs(res, , , , , s, on, off, );
vector<string> ret;
for (set<string>::iterator it = res.begin(); it != res.end(); it++) ret.push_back(*it);
sort(ret.begin(), ret.end());
) {
fout << "IMPOSSIBLE" << endl;
;
}
; i < ret.size(); i++) {
fout << ret[i] << endl;
}
;
}
USACO Section 2.2: Party Lamps的更多相关文章
- USACO Section 1.3 题解 (洛谷OJ P1209 P1444 P3650 P2693)
usaco ch1.4 sort(d , d + c, [](int a, int b) -> bool { return a > b; }); 生成与过滤 generator&& ...
- 【USACO 2.2】Party Lamps
四种开关,n盏灯,1:改变所有灯状态,2:改变奇数灯状态,3:改变偶数灯状态,4:改变3k+1灯状态 给你按开关的总次数c和部分灯限制条件(开或关),一开始都是开着的.($c \leq 10000,n ...
- USACO Section 3.3: Riding the Fences
典型的找欧拉路径的题.先贴下USACO上找欧拉路径的法子: Pick a starting node and recurse on that node. At each step: If the no ...
- USACO Section 3.3 Camlot(BFS)
BFS.先算出棋盘上每个点到各个点knight需要的步数:然后枚举所有点,其中再枚举king是自己到的还是knight带它去的(假如是knight带它的,枚举king周围的2格(网上都这么说,似乎是个 ...
- [IOI1996] USACO Section 5.3 Network of Schools(强连通分量)
nocow上的题解很好. http://www.nocow.cn/index.php/USACO/schlnet 如何求强连通分量呢?对于此题,可以直接先用floyd,然后再判断. --------- ...
- USACO Section 5.3 Big Barn(dp)
USACO前面好像有类似的题目..dp(i,j)=min(dp(i+1,j),dp(i+1,j+1),dp(i,j+1))+1 (坐标(i,j)处无tree;有tree自然dp(i,j)=0) .d ...
- USACO Section 1.3 Prime Cryptarithm 解题报告
题目 题目描述 牛式的定义,我们首先需要看下面这个算式结构: * * * x * * ------- * * * <-- partial product 1 * * * <-- parti ...
- USACO Section 1.1 Your Ride Is Here 解题报告
题目 问题描述 将字符串转变为数字,字母A对应的值为1,依次对应,字母Z对应的值为26.现在有一个字符串,将其中的每个字符转变为数字之后进行累乘,最终的结果对47求余数. 题目给你两个字符串,其中的字 ...
- USACO Section 1.1-1 Your Ride Is Here
USACO 1.1-1 Your Ride Is Here 你的飞碟在这儿 众所周知,在每一个彗星后都有一只UFO.这些UFO时常来收集地球上的忠诚支持者.不幸的是,他们的飞碟每次出行都只能带上一组支 ...
随机推荐
- Xamarin.Android之转换,呼叫,查看历史纪录
Xamarin.Android之转换,呼叫,查看历史纪录 E文文章. 功能:能将输入的字母转换成相应的数字.并且能呼叫出去.能查看呼叫的历史纪录. 界面代码如下: <?xml version=& ...
- android开发实现静默安装(root权限)
方式是将应用设置为内置的系统应用,注意事system/app目录下面,采用copy2SystemApp()方法就可以,注意chmod 777的权限,若是直接将apk拷贝到system/app目录,没有 ...
- ReactJS入门
React介绍 React是facebook开发基于组件驱动开发(CDD ) 的UI类库,相对于双向绑定的类库,如AngularJS,它采用单向数据流绑定.通过采用虚拟DOM的概念,是的他在性能和处理 ...
- HDU 5800 To My Girlfriend 背包
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5800 To My Girlfriend Time Limit: 2000/2000 MS (Java ...
- 开始学习C++ Templates
设计模式的学习以及各种设计模式的C++实现已经告一段落了,解释器模式和迭代器模式,以及模版办法简单的看了一下. 画UML图的时候再重点学习 从今天开始学习Templates.
- 【BZOJ】【1004】【HNOI2008】Cards
Burnside/Polya+背包DP 这道题目是等价类计数裸题吧……>_> 题解:http://m.blog.csdn.net/blog/njlcazl_11109/8316340 啊其 ...
- 【BZOJ】【3004】吊灯
思路题 要将整棵树分成大小相等的连通块,那么首先我们可以肯定的是每块大小x一定是n的约数,且恰好分成$\frac{n}{x}$块,所以我有了这样一个思路:向下深搜,如果一个节点的size=x,就把这个 ...
- 重构:CSS也面向对象
最初接触到面向对象的CSS还是因为项目中的CSS已经超过八千行,缺乏约束和管理,在近期或者是不远的将来,有迫切的要求需要重构.在前端重构中,我们已经讨论过了JavaScript面向对象的重构,在这个时 ...
- POJ 1065 Wooden Sticks
Wooden Sticks Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16262 Accepted: 6748 Descri ...
- 如何在帝国cms后台菜单栏中添加删除链接?
下午测试一个网上下载经过二次开发的帝国cms系统,还原完数据进入后台ytkah发现菜单栏多出了几个链接,有点不习惯,就想着怎么把它去掉.由于自己用的win7系统,搜索时没有像xp那样可以搜索包含某字符 ...