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的更多相关文章

  1. Codeforces 295C Greg and Friends BFS

    Greg and Friends BFS的过程中维护一下方案数. 我个人感觉不是很好想, 但是写出来之后怎么感觉这题这么SB啊啊. #include<bits/stdc++.h> #def ...

  2. 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 ...

  3. ACM - 最短路 - CodeForces 295B Greg and Graph

    CodeForces 295B Greg and Graph 题解 \(Floyd\) 算法是一种基于动态规划的算法,以此题为例介绍最短路算法中的 \(Floyd\) 算法. 我们考虑给定一个图,要找 ...

  4. Codeforces 295A Greg and Array

    传送门 A. Greg and Array time limit per test 1.5 seconds memory limit per test 256 megabytes input stan ...

  5. 那些年我们写过的三重循环----CodeForces 295B Greg and Graph 重温Floyd算法

    Greg and Graph time limit per test 3 seconds memory limit per test 256 megabytes input standard inpu ...

  6. Codeforces 296C Greg and Array

    数据结构题.个人认为是比较好的数据结构题.题意:给定一个长度为n的数组a,然后给定m个操作序列,每个操作:l, r, x将区间[l, r]内的元素都增加a,然后有k个查询,查询形式是对于操作序列x,y ...

  7. [CodeForces - 296D]Greg and Graph(floyd)

    Description 题意:给定一个有向图,一共有N个点,给邻接矩阵.依次去掉N个节点,每一次去掉一个节点的同时,将其直接与当前节点相连的边和当前节点连出的边都需要去除,输出N个数,表示去掉当前节点 ...

  8. CodeForces 295B Greg and Graph (floyd+离线)

    <题目链接> 题目大意:给定$n$个点的有向完全带权图$(n\leq500)$,现在进行$n$次操作,每次操作从图中删除一个点(每删除一个点,都会将与它相关联的边都删除),问你每次删点之前 ...

  9. Codeforces 295D - Greg and Caves(dp)

    题意: 给出一个 \(n \times m\) 的矩阵,需对其进行黑白染色,使得以下条件成立: 存在区间 \([l,r]\)(\(1\leq l\leq r\leq n\)),使得第 \(l,l+1, ...

随机推荐

  1. Authentication for the REST APIs

    HTTP基本认证原理 在HTTP协议进行通信的过程中,HTTP协议定义了基本认证过程以允许HTTP服务器对WEB浏览器进行用户身份认证的方法,当一个客户端向HTTP服务器进行数据请求时,如果客户端未被 ...

  2. Vijos P1062 迎春舞会之交谊舞

    题目链接:https://vijos.org/p/1062 题意:输入n(n <= 1500)个女生左边有多少个男生.每个女生都和她左边最近的男生跳舞. 输出每个女生到可以与之跳舞的男生之间有几 ...

  3. homework-Agile Software Development

    对敏捷开发的一些思考 这周的作业是对敏捷开发的相关阅读和思考. 在阅读的过程中,可以看到作者是一位具有丰富编程经验的大师.在开发的经历中,作者经历了极限编程等开发过程,但是在作者的多年经验中,作者还是 ...

  4. 【记录】让人淡疼的BUG之参数传送错误

    前言 面试的时候往往容易被面试官问到:“说说你遇到过的比较重大或经典的Bug有哪些,能说一说吗?”我被问时脑海的反应是:“尼玛,这个我从来没有刻意记!一时半会咋想得起来,然后还是没想起来或者是随意给了 ...

  5. Linux内核spin_lock与spin_lock_irq分析

    http://blog.csdn.net/zhanglei4214/article/details/6837697

  6. Altium Designer 常用快捷键总结

    原理图:1:按住shift  拖动某个元件,可快速复制.2:按住鼠标滚轮 鼠标上下滑动 放大缩小.3:按住Ctrl 按住鼠标右键 鼠标上下滑动也放大缩小.4:按住Ctrl 拖动某个元件 可以移动位置 ...

  7. Pascal Game Development with Jason McMillen

    In this much belated episode I talk with Jason McMillen of Pascal Game Development. We discuss the s ...

  8. c++模板注意事项

    c++模板类 分类: C++2012-08-20 21:28 7108人阅读 评论(2) 收藏 举报 c++编译器instantiationiostreamlinker编程 c++模板类 分类: 数据 ...

  9. MySQL主从复制中断处理一例

    收到mysql主从中断报警邮件,马上登上服务器查看,发现是中继日志损坏. Show slave status\G,提示中继日志损坏,按以往的做法,根据提示重新指定合适的日志文件以及pos点.  Rel ...

  10. tomcat docBase 和 path

    <Context docBase="zjzc-web-api" path="/api" reloadable="false"/> ...