Codeforces 295C Greg and Friends BFS】的更多相关文章

Greg and Friends BFS的过程中维护一下方案数. 我个人感觉不是很好想, 但是写出来之后怎么感觉这题这么SB啊啊. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII pair<…
One day Greg and his friends were walking in the forest. Overall there were n people walking, including Greg. Soon he found himself in front of a river. The guys immediately decided to get across the river. Luckily, there was a boat by the river bank…
BFS+DP.dp[i][j][0]表示有i个50kg,j个100kg的人在左岸,dp[i][j][1]表示有i个50kg,j个100kg的人在右岸.用BFS求最短路的时候记录到达该状态的可能情况. #include <iostream> #include <stdio.h> #include <string.h> #include <queue> using namespace std; typedef long long LL; #define maxn…
CodeForces 295B Greg and Graph 题解 \(Floyd\) 算法是一种基于动态规划的算法,以此题为例介绍最短路算法中的 \(Floyd\) 算法. 我们考虑给定一个图,要找出 \(i\) 号点到 \(j\) 号点的最短路径.则该最短路径只有两种可能: \(i\) 号点直接到达 \(j\) 号点的路径中产生最短路径 \(i\) 号点经过一些中间点到达 \(j\) 号点的路径中产生最短路径 我们添加一个点 \(k\),使得 \(i\) 号点到 \(j\) 号点再添加后产生…
F. FloodTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/F Description We all know that King Triton doesn't like us and therefore shipwrecks, hurricanes and tsunami do happen. But being bored with the same routine…
http://codeforces.com/problemset/problem/540/C       Ice Cave Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 540C Description You play a computer game. Your character stands on some lev…
链接: https://codeforces.com/contest/1283/problem/D 题意:给定n个不同的整数点,让你找m个不同的整数点,使得这m个点到到这n个点最小距离之和最小. 思路:贪心一下,首先每个点的x+1和x-1两个坐标到这个点的距离是最短的,之后是x+2,x-2,再之后是x+3,x-3,那么可以想到bfs,首先把n个点存入队列中,找与他们距离为1的点,之后再bfs距离为2的点,如此这个过程直到找到m个点. AC代码: #include<iostream> #incl…
/* 题意:求出多个全排列的lcs! 思路:因为是全排列,所以每一行的每一个数字都不会重复,所以如果有每一个全排列的数字 i 都在数字 j的前面,那么i, j建立一条有向边! 最后用bfs遍历整个图,求出源点到每一个点的距离,其中最大的距离就是最长的公共子序列的长度! */ #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<queue&g…
题目链接:http://codeforces.com/problemset/problem/689/B 题目大意: 留坑 明天中秋~…
传送门 A. Greg and Array time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input output standard output Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 ≤ li ≤ ri ≤ n). To a…