题目描述

约翰和他的奶牛组建了一只乐队“后街奶牛”,现在他们正在牧场里排练.奶牛们分成一堆 一堆,共1000)堆.每一堆里,30只奶牛一只踩在另一只的背上,叠成一座牛塔.牧场 里还有M(1 < M < 1000)个高高的草垛.

作为出色的指挥家,约翰可以通过口哨指挥奶牛们移动.他的口哨有四个音,分别能使所有 的牛塔向东南西北四个方向移动一格.

每一次,当一个牛塔到达了一个草垛所在的格子,牛塔最上方的奶牛就会跳到草垛上,而且 不再下来,而其他奶牛仍然呈塔状站在草垛所在的格子里.当牛塔只剩一只奶牛时,这只奶牛也 会跳到草垛上.

突然,约翰大惊失色:原来邻家的奶缸爆炸了!滚滚而下的牛奶正朝着约翰的牧场冲来,不久就要将牧场淹没.约翰必须马上行动,用口哨声挽救奶牛们的生命.他要指挥奶牛尽量多地跳 上草操,草操上的奶牛将不会被淹死.

约翰还有K次吹口哨的机会.那他最多还能救多少奶牛呢?请计算最多能挽救的奶牛数,以及 达到这个数目约翰需要吹的口哨调子序列.序列用E,W,S,N表示东西南北.如果有多种序列能达到 要求,输出作为字符串最小的.

输入输出格式

输入格式:

  • Line 1: Three space-separated integers: N, M, and K

  • Lines 2..N+1: Line i+1 describes the X,Y location of a stack of 30 cows using two space-separated integers: X_i and Y_i

  • Lines N+2..N+M+1: Line i+N+1 describes the X,Y location of a haystack using two space-separated integers: X_i and Y_i

输出格式:

  • Line 1: A single integer that is the most number of cows that can be saved.

  • Line 2: K characters, the lexicographically least sequence of commands FJ should issue to maximize the number of cows saved.

输入输出样例

输入样例#1:

3 6 3
3 4
6 2
5 7
8 2
9 2
6 4
5 4
6 7
8 7
输出样例#1:

6
EEE

说明

Use the 'east' whistle three times, at which point the milk floods the area. Each haystack ends up saving 1 cow.

dp 恶心。。

一个神奇的问题:

考试时我读不完数据 (#‵′)靠

前面的很正常

m个草都是0的读不完。。

读入优化超时

cin scanf读不进去 直接炸内存。。

屠龙宝刀点击就送

#include <cstring>
#include <cstdio>
#define N 35
#define M 2005
#define INF 0x3f3f3f3f
int n,m,k,ans=,x[M],y[M],li=,lj=,f[N<<][N<<][N],newmap[N<<][N<<],Map[M][M],fx[]={-,,,},fy[]={,-,,};
char pre[N<<][N<<][N],pick[N];
inline int max(int a,int b) {return a>b?a:b;}
void init_map()
{
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
for(int l=;l<=n;l++)
{
int X=x[l],Y=y[l];
if(X+i-<=||Y+j-<=||X+i->||Y+j->) continue;
newmap[i][j]+=Map[X+i-][Y+j-];
}
}
}
}
int main()
{
// freopen("dance.in","r",stdin);freopen("dance.out","w",stdout);
pick[]='W',pick[]='S',pick[]='N',pick[]='E';
scanf("%d%d%d",&n,&m,&k);
for(int i=;i<=n;i++) scanf("%d%d",&x[i],&y[i]);
for(int x,y,i=;i<=m;i++)
{
scanf("%d%d",&x,&y);
Map[x][y]++;
}
init_map();
for(int i=;i<=k;i++)
for(int j=;j<=;j++)
for(int l=;l<=;l++)
f[j][l][i]=-INF,pre[j][l][i]='Z';
f[][][]=;
for(int i=;i<=k;i++)
{
for(int j=;j<=;j++)
{
for(int l=;l<=;l++)
{
f[j][l][i]=max(max(f[j-][l][i-],f[j][l-][i-]),max(f[j][l+][i-],f[j+][l][i-]))+newmap[j][l];
if(i==k) ans=max(ans,f[j][l][i]);
}
}
}
for(int i=;i<=;i++)
for(int j=;j<=;j++)
if(f[i][j][k]==ans)
pre[i][j][k]='A';
for(int l=k-;l>=;l--)
{
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
for(int o=;o<;o++)
{
if(f[i][j][l]+newmap[i+fx[o]][j+fy[o]]==f[i+fx[o]][j+fy[o]][l+]&&pre[i+fx[o]][j+fy[o]][l+]<'Z')
pre[i][j][l]=pick[o];
}
}
}
}
printf("%d\n",ans);
for(int i=;i<k;i++)
{
printf("%c",pre[li][lj][i]);
if(pre[li][lj][i]=='E') li++;
else if(pre[li][lj][i]=='N') lj++;
else if(pre[li][lj][i]=='S') lj--;
else if(pre[li][lj][i]=='W') li--;
}
return ;
}

洛谷 P2905 [USACO08OPEN]农场危机Crisis on the Farm的更多相关文章

  1. 洛谷P2905 [USACO08OPEN]农场危机Crisis on the Farm

    P2905 [USACO08OPEN]农场危机Crisis on the Farm 题目描述 约翰和他的奶牛组建了一只乐队“后街奶牛”,现在他们正在牧场里排练.奶牛们分成一堆 一堆,共1000)堆.每 ...

  2. bzoj1605 / P2905 [USACO08OPEN]农场危机Crisis on the Farm

    P2905 [USACO08OPEN]农场危机Crisis on the Farm 发现总步数$k<=30$,考虑用$k$瞎搞 设$f[u][i][j]$表示已经吹$u$次哨,全体奶牛向右走$i ...

  3. P2905 [USACO08OPEN]农场危机Crisis on the Farm

    传送门 DP 设 f [ i ] [ j ] [ k ] 表示已经走了 i 步,向上走了 j 步,向右走了 k 步时能拯救的最多奶牛数(j,k可以为负,表示反向) 设 g [ i ] [ j ] 表示 ...

  4. P2905 [USACO08OPEN]农场危机Crisis on the Farm(简单dp+麻烦“回溯”)

    惯例,化简题意(看长短决定难度) 一块草坪上有两种点(姑且称为a和b),各有坐标,现在能同时使所有a点向东西南北任意一个方向移动一个单位,若a点与b点重合,则答案增加重合数,求答案的最大值并且求出这个 ...

  5. 洛谷——P2908 [USACO08OPEN]文字的力量Word Power

    P2908 [USACO08OPEN]文字的力量Word Power 题目描述 Farmer John wants to evaluate the quality of the names of hi ...

  6. 洛谷——P2910 [USACO08OPEN]寻宝之路Clear And Present Danger

    P2910 [USACO08OPEN]寻宝之路Clear And Present Danger 题目描述 Farmer John is on a boat seeking fabled treasur ...

  7. 洛谷 P3079 [USACO13MAR]农场的画Farm Painting

    P3079 [USACO13MAR]农场的画Farm Painting 题目描述 After several harsh winters, Farmer John has decided it is ...

  8. 洛谷 P2908 [USACO08OPEN]文字的力量Word Power

    P2908 [USACO08OPEN]文字的力量Word Power 题目描述 Farmer John wants to evaluate the quality of the names of hi ...

  9. 洛谷 P2906 [USACO08OPEN]牛的街区Cow Neighborhoods | Set+并查集

    题目: https://www.luogu.org/problemnew/show/P2906 题解: 垃圾水题 #include<cstdio> #include<algorith ...

随机推荐

  1. 《深入分析Java Web技术内幕》读后感(Session、cookie)

    第10章 P263 理解Cookie 理解Session Session如何工作的

  2. linux下安装mysql的三种方法:rpm包安装、yum安装、源码包安装

    1 安装MySQL数据库服务器安装方法一://查询系统自带的数据库rpm -qa | grep -i mysql //卸载查询到的所有mysqlrpm -e --nodeps mysql-libs-5 ...

  3. 2.5玩转xargs

    我们可以利用管道将一个命令的stdout(标准输出)重定向到另一个命令的stdin(标准输入).有些命令只能以命令行参数的形式接受数据,而无法通过stdin接受数据流.这时候就没法使用管道.那么xar ...

  4. js基础(补10.10)

    1.内嵌式: <html> <head> <title></title> </head> <body> <a href=& ...

  5. android fragment ontouch 事件

    由于fragment是存在于activity之中的,所以触摸事件会被activity首先得到. 为了在fragment中执行ontouch方法,需要做如下处理: mFragment = new Tab ...

  6. ACM-ICPC2018北京网络赛 Tomb Raider(暴力)

    题目2 : Tomb Raider 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Lara Croft, the fiercely independent daughte ...

  7. sqlserver2012——逻辑运算符

    ALL 如果一组的比较都为TRUE,则结果为true ANY如果玉足比较中任何一个为true,则结果为true AND 两个boll都为TRUE,则结果为TRUE OR 两个BOLL任何一个TRUE, ...

  8. nginx是如何处理一个请求的(包含https配置)

    配置https首先要有ssl证书,这个证书目前阿里有免费的,但如果自己做实验,也是可以自签证书,只不过不受信 openssl genrsa -des3 -out server.key 1024     ...

  9. 开源:基于Android的室内定位WiFi,iBeacon数据采集和定位脚本

    最近有同学联系我,也在一些群里看到有新手同学挣扎在怎么获取定位数据,不知从何下手.所以整理并开源这个基于Android的数据采集软件和基于python的KNN定位demo,算是为新手同学建立一个Bas ...

  10. java反射机制应用之动态代理

    1.静态代理类和动态代理类区别 静态代理:要求被代理类和代理类同时实现相应的一套接口:通过代理类的对象调用重写接口的方法时,实际上执行的是被代理类的同样的 方法的调用. 动态代理:在程序运行时,根据被 ...