题目链接:http://codeforces.com/problemset/problem/377/A 题解: 有tot个空格(输入时统计),把其中k个空格变为wall,问怎么变才能使得剩下的空格依然为连通的.把问题反过来,其实就是求tot-k的连通图.dfs:在搜索过的空格中做个标记,同时更新连通个数. 代码如下: #include<cstdio>//hdu3183 CodeForces 377A dfs #include<cstring> #include<cmath&g…
A. Maze 题目连接: http://codeforces.com/contest/377/problem/A Description Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and h…
377A Maze 大意: 给定棋盘, 保证初始所有白格连通, 求将$k$个白格变为黑格, 使得白格仍然连通. $dfs$回溯时删除即可. #include <iostream> #include <functional> #include <sstream> #include <algorithm> #include <cstdio> #include <math.h> #include <set> #include &…
D. Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Alyona has a tree with n vertices. The root of the tree is the vertex 1. In each vertex Alyona wrote an positive intege…
题目链接:http://codeforces.com/contest/742/problem/E 题意: 有一个环形的桌子,一共有n对情侣,2n个人,一共有两种菜. 现在让你输出一种方案,满足以下要求: 情侣间吃不同的菜 相邻的三个人不能都吃同一种菜 输出任意一个解: 先将相邻的两个人连边,这样就满足了3个人不吃同样一种菜. 情侣间连边. 图中就不存在奇数环. 那么就一定存在解.然后DFS染色就OK 了. #include <bits/stdc++.h> using namespace std…
题目链接:http://codeforces.com/problemset/problem/510/B 题意:判断图中是否有某个字母成环 思路:直接dfs就好了,注意判断条件:若下一个字母与当前字母相同且已搜过,则存在满足题意的环 代码: #include <bits/stdc++.h> #define MAXN 60 using namespace std; int mp[MAXN][MAXN], vis[MAXN][MAXN], m, n; ][]={, , , , -, , , -};…
题目链接: http://codeforces.com/contest/378/problem/E 题意: dota选英雄,现在有n个英雄,m个回合,两支队伍: 每一回合两个选择: b 1,队伍一ban掉一个英雄,或是跳过这个回合 p 1,队伍1选一个英雄 现在每个队伍都是最优决策,问最后队伍一的英雄实力和-队伍二的英雄实力和. 题解: 状压dp,决策要倒过来做,也就是dp出后面回合的决策的基础上设计出对自己当前回合对自己最有利的决策.. 注意:只有top m的英雄有可能被选,其他的都不可能被选…
D. Developing Game 题目连接: http://www.codeforces.com/contest/377/problem/D Description Pavel is going to make a game of his dream. However, he knows that he can't make it on his own so he founded a development company and hired n workers of staff. Now…
C. Captains Mode 题目连接: http://codeforces.com/contest/377/problem/C Description Kostya is a progamer specializing in the discipline of Dota 2. Valve Corporation, the developer of this game, has recently released a new patch which turned the balance of…
B. Preparing for the Contest 题目连接: http://codeforces.com/contest/377/problem/B Description Soon there will be held the world's largest programming contest, but the testing system still has m bugs. The contest organizer, a well-known university, has n…