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, ...
随机推荐
- We7——很有意思的一个开源CMS
目前做门户.做网站,基本上都需要用到一个系统,那就是CMS内容管理系统:现在开源产品有很多,笔者也是从事这个行业的,国内的各大CMS提供商基本上都试用过,今天向大家推荐一款很有意思的产品——We7CM ...
- PL/SQL — 隐式游标
一.隐式游标的定义及其属性 定义 隐式游标由系统自动定义,非显示定义游标的DML语句即被赋予隐式游标属性.其过程由oracle控制,完全自动化.隐式游标的名称是SQL,不能对SQL游标显式地执行OPE ...
- Grails连接外部数据库注意事项Could not determine Hibernate dialect for database name [Oracle]!
初次使用Grails时,使用其内置数据库,一直不会出错,但迁移到外部数据库时会出错Could not determine Hibernate dialect for database name [Or ...
- 搭建 Win CE6.0 设备开发环境
1.操作系统最好基于Windows XP.Vista.Win7 或以上的版本对ActiveSync软件不支持 2.安装VS2008,以及SP1 (一定要装SP1) 3.安装ActiveSync 4. ...
- BZOJ 1709: [Usaco2007 Oct]Super Paintball超级弹珠
Description 奶牛们最近从著名的奶牛玩具制造商Tycow那里,买了一套仿真版彩弹游戏设备(类乎于真人版CS). Bessie把她们玩游戏草坪划成了N * N(1 <= N<= 1 ...
- PHP漏洞全解(二)-命令注入攻击
本文主要介绍针对PHP网站常见的攻击方式中的命令攻击.Command Injection,即命令注入攻击,是指这样一种攻击手段,黑客通过把HTML代码输入一个输入机制(例如缺乏有效验证限制的表格域)来 ...
- PHP basename() 函数
定义和用法 basename() 函数返回路径中的文件名部分. 语法 basename(path,suffix) 参数 描述 path 必需.规定要检查的路径. suffix 可选.规定文件扩展名.如 ...
- UVA 10608 Friends
题目大意:共有n个人,m对人为已知的朋友关系,而且这种关系具有传递性,也就是A与B,B与C是朋友,可以确定A与C是朋友,求一个人数最多的朋友团体. bfs就可以了,遇到未访问的结点,加入队列并且朋人数 ...
- 对于Unicode编码在js中和html中
1.对于Unicode在js中 var a="\u9102WQW121" 中"\"是需要转义的,直接在页面输出的效果
- ActionBar官方教程(1)简介及各区域介绍
Action Bar The action bar is a window feature that identifies the user location, and provides user a ...