Codeforces 295C Greg and Friends
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 55
#define INF 0xffffffff
const LL mod = ; struct Point{
int f, t, s;
Point(){}
Point(int _f, int _t, int _s):
f(_f), t(_t), s(_s){}
}; LL dp[maxn][maxn][];
LL C[maxn][maxn];
int hash[maxn][maxn][]; int bfs(int nf, int nt, int cap){
queue<Point> Q;
dp[nf][nt][] = ;
hash[nf][nt][] = ;
Q.push(Point(nf, nt, ));
while(!Q.empty()){
Point c = Q.front();Q.pop();
int cf = c.f, ct = c.t, cs = c.s;
for(int i = ; i <= c.f; i ++){
if(i* > cap) break;
for(int j = ; j <= c.t; j ++){
if(i* + j* > cap) continue;
if(i* + j* <= ) continue; int lf = c.f - i, lt = c.t - j;
if(hash[nf - lf][nt - lt][!cs]==INF){
hash[nf - lf][nt - lt][!cs] = hash[cf][ct][cs] + ;
LL tmp = C[cf][i]*C[ct][j]%mod;
dp[nf - lf][nt - lt][!cs] += (tmp*dp[cf][ct][cs]%mod);
dp[nf - lf][nt - lt][!cs]%=mod;
Q.push(Point(nf-lf, nt-lt, !cs));
}
else if(hash[nf - lf][nt - lt][!cs]==hash[cf][ct][cs] + ){
LL tmp = C[cf][i]*C[ct][j]%mod;
dp[nf - lf][nt - lt][!cs] += (tmp*dp[cf][ct][cs]%mod);
dp[nf - lf][nt - lt][!cs]%=mod;
}
}
}
}
return hash[nf][nt][];
} void init(){
C[][] = ;
for(int i = ; i <= ; i ++){
C[i][] = ;
for(int j = ; j <= i; j ++){
C[i][j] = (C[i-][j-] + C[i-][j])%mod;
}
}
} int main()
{
init();
//freopen("test.in", "r", stdin);
for(int n, k, nf, nt; scanf("%d%d", &n, &k)!=EOF; ){
memset(dp, , sizeof(dp));
memset(hash, 0xff, sizeof(hash));
nf = nt = ;
for(int i = , x; i < n; i ++){
scanf("%d", &x);
if(x==) nf ++;
else nt ++;
}
bfs(nf, nt, k);
printf("%d\n%I64d\n", hash[nf][nt][], dp[nf][nt][]);
}
return ;
}
Codeforces 295C Greg and Friends的更多相关文章
- Codeforces 295C Greg and Friends BFS
Greg and Friends BFS的过程中维护一下方案数. 我个人感觉不是很好想, 但是写出来之后怎么感觉这题这么SB啊啊. #include<bits/stdc++.h> #def ...
- codeforces 295C Greg and Friends(BFS+DP)
One day Greg and his friends were walking in the forest. Overall there were n people walking, includ ...
- ACM - 最短路 - CodeForces 295B Greg and Graph
CodeForces 295B Greg and Graph 题解 \(Floyd\) 算法是一种基于动态规划的算法,以此题为例介绍最短路算法中的 \(Floyd\) 算法. 我们考虑给定一个图,要找 ...
- Codeforces 295A Greg and Array
传送门 A. Greg and Array time limit per test 1.5 seconds memory limit per test 256 megabytes input stan ...
- 那些年我们写过的三重循环----CodeForces 295B Greg and Graph 重温Floyd算法
Greg and Graph time limit per test 3 seconds memory limit per test 256 megabytes input standard inpu ...
- Codeforces 296C Greg and Array
数据结构题.个人认为是比较好的数据结构题.题意:给定一个长度为n的数组a,然后给定m个操作序列,每个操作:l, r, x将区间[l, r]内的元素都增加a,然后有k个查询,查询形式是对于操作序列x,y ...
- [CodeForces - 296D]Greg and Graph(floyd)
Description 题意:给定一个有向图,一共有N个点,给邻接矩阵.依次去掉N个节点,每一次去掉一个节点的同时,将其直接与当前节点相连的边和当前节点连出的边都需要去除,输出N个数,表示去掉当前节点 ...
- CodeForces 295B Greg and Graph (floyd+离线)
<题目链接> 题目大意:给定$n$个点的有向完全带权图$(n\leq500)$,现在进行$n$次操作,每次操作从图中删除一个点(每删除一个点,都会将与它相关联的边都删除),问你每次删点之前 ...
- Codeforces 295D - Greg and Caves(dp)
题意: 给出一个 \(n \times m\) 的矩阵,需对其进行黑白染色,使得以下条件成立: 存在区间 \([l,r]\)(\(1\leq l\leq r\leq n\)),使得第 \(l,l+1, ...
随机推荐
- Chapter 10 EF 6 Support
http://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html
- use worker without js file
var blob = new Blob(['onmessage=function(e){postMessage(e.data);}']); debugger; // Obtain a blob URL ...
- appcache checking update
<!DOCTYPE html> <html manifest="a.appcache"> <head> <title></ti ...
- 如何使用 Xcode Targets 管理开发和生产版本?
在开始此教程之前,我们假设你已经完成了应用程序的开发和测试,现在准备提交生产发布.问题是,某些 Web 服务 URLs 指向测试服务器,而 API keys 则为测试环境而配置.在提交应用程序给苹果审 ...
- Codeforces Round #215 (Div. 1)
A Sereja and Algorithm 题意:给定有x,y,z组成的字符串,每次询问某一段s[l, r]能否变成变成zyxzyx的循环体. 分析: 分析每一段x,y,z数目是否满足构成循环体,当 ...
- UVA 10273 Eat or Not to Eat?
这个题目一直以为是要用图论知识来做,可是一点建图的思绪都没有,后来知道暴力便可破之.由于牛的产奶周期最大为10,1.2.3.....10的最小公倍数是MT = 2520,所以把MT作为最大的周期,然后 ...
- ANDROID_MARS学习笔记_S01原始版_023_MP3PLAYER004_同步显示歌词
一.流程分析 1.点击播放按钮,会根据lrc名调用LrcProcessor的process()分析歌词文件,得到时间队列和歌词队列 2.new一个hander,把时间队列和歌词队列传给自定义的线程类U ...
- 解读分库分表中间件Sharding-JDBC
[编者按]数据库分库分表从互联网时代开启至今,一直是热门话题.在NoSQL横行的今天,关系型数据库凭借其稳定.查询灵活.兼容等特性,仍被大多数公司作为首选数据库.因此,合理采用分库分表技术应对海量数据 ...
- 解析rss和atom文件出现乱码问题
try { String xmlString = new String(response.data, Charset.forName("UTF-8")); XmlPullParse ...
- TortoiseSVN设置比较工具为BeyondCompare
1. "C:\Beyond Compare 4\BCompare.exe" %base %mine /title1=%bname /title2=%yname /leftread ...