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时常来收集地球上的忠诚支持者.不幸的是,他们的飞碟每次出行都只能带上一组支 ...
随机推荐
- fwrite ,fprintf的作用与区别
1.概念和作用 fwrite是C语言函数,指向文件写入一个数据块,写入的是 fprintf是C/C++中的一个格式化写-库函数,其作用是格式输出到一个流/文件中:原型是int fprintf( FIL ...
- SQLServer BCP 命令的使用
现在有一个包含数据的文件,每个字段用“|”分隔,现在要把这些数据导入到数据库的表中. 数据文件如下: R001|20150710 可以使用如下命令: bcp testDB.dbo.testTable ...
- RegExp.exec和String.match深入理解
今天在重新阅读<JavaScript权威指南>的RegExp和String的时候,看到了2个比较容易混淆的函数:RegExp的exec和String的match 这2个函数都是从指定的字符 ...
- js的全局函数
JS的全局函数,全局函数和window对象的函数不一样. 全局函数不属于任何一个内置对象. JS包含以下7个全局函数,用于一些常用的功能: escape(),unescape(); //编码,解码. ...
- 编写一函数用来实现左右循环移位。函数原型为move(value,n);n>0时右移n位,n<0时左移|n|位。
#include<stdio.h> #include<stdlib.h> int main(){ setbuf(stdout,NULL); int move(int,int); ...
- PowerDesigner(八)-面向对象模型(用例图,序列图,类图,生成Java源代码及Java源代码生成类图)(转)
面向对象模型 面向对象模型是利用UML(统一建模语言)的图形来描述系统结构的模型,它从不同角度实现系统的工作状态.这些图形有助于用户,管理人员,系统分析人员,开发人员,测试人员和其他人员之间进行信息交 ...
- PowerDesigner(五)-概念数据模型(CDM生成LDM,PDM和OOM)(转)
概念数据模型 概念数据模型(Conceptual Data Model,CDM):表达的是数据整体逻辑结构,该结构独立于任何软件和数据存储结构,即它只是系统分析人员,应用程序设计人员,维护人员和用户之 ...
- 一系列JavaScript的基础工具
在我们的bootcamp训练营中,学员们介绍了一些工具和库来扩展他们代码的能力.Kalina,目前我们JavaScript学员中的一员,列举了这些工具,想和其它爱好代码的小伙伴一起分享. 点击看大图 ...
- 驱动笔记 - Makefile
ifneq ($(KERNELRELEASE),) obj-m := hello.ohello-objs := main.o add.o else KDIR := /lib/modules/2.6.1 ...
- ZOJ 1115 Digital Roots(简单,字符串与数)
题目 //好一道水水题,可是我居然也错了那么多次,后来百度来发现是因为数据数位可能很长很长,要用字符串数组... //简单 //有坑啊——数据可能很大很大,要用字符串表示! #include<s ...