1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
来源:互联网 发布:35互联域名管理平台 编辑:程序博客网 时间:2024/06/08 07:07
1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 920 Solved: 594
[Submit][Status][Discuss]
Description
Farmer John养了N(1 <= N <= 5,000)头奶牛,每头牛都有一个不超过32位二进制数的正整数编号。FJ希望奶牛们在进食前,能按编号从小到大的顺序排好队,但奶牛们从不听他的话。为了让奶牛们养成这个习惯,每次开饭时,FJ从奶牛中顺序地挑出一些,这些奶牛的编号必须按挑出的顺序递增。然后FJ让被挑出的奶牛们吃饭——其他奶牛就只能饿肚子了。 现在,你得到了这一次开饭前队伍中从前到后所有奶牛的编号。奶牛们想请你计算一下,按照FJ的规定,最多有多少头奶牛能吃上饭? 比如说,有11头奶牛按以下顺序排好了队(数字代表奶牛的编号) 2 5 18 3 4 7 10 9 11 8 15 对于这个队列,最多可以让7头奶牛吃上饭,她们的编号分别为2,3,4,7,10,11,15。队列2,5,3,10,15是不合法的,因为第3头奶牛的编号(3)小于她前面一头奶牛的编号(5)。
Input
* 第1行: 一个整数,N * 第2..?行: 除了最后一行,每一行都包含恰好20个用空格隔开的整数,依次表 示队伍中从前到后的奶牛的编号。如果N不能整除20,那么最后一 行包含的数字不到20个
Output
* 第1行: 输出按照FJ的规定,最多可以挑出的奶牛的数目
Sample Input
11
2 5 18 3 4 7 10 9 11 8 15
2 5 18 3 4 7 10 9 11 8 15
Sample Output
7
HINT
Source
模板题不解释。。。。日常刷水。。。。
lis
#include<iostream>#include<algorithm>#include<cstring>#include<string>#include<climits>#include<cmath>#include<cstdio>#include<cstdlib>#include<queue>#include<stack>#include<map>#include<set>#define N 1001using namespace std;int n,m;int mp[N][N];int vis[N][N][2];int dx[4]={0,1,0,-1};int dy[4]={1,0,-1,0};struct node{int x,y,c;bool f;}u,v;queue<node>Q;int ans=0x3f3f3f3f;int main(){scanf("%d%d",&m,&n);for(int i=1;i<=n;i++)for(int j=1;j<=m;j++){scanf("%d",&mp[i][j]);if(mp[i][j]==2)u.x=i,u.y=j,u.f=0,u.c=0;}Q.push(u);memset(vis,0x3f3f3f3f,sizeof(vis));while(!Q.empty()){u=Q.front();Q.pop();if(vis[u.x][u.y][u.f]<u.c)continue;if(mp[u.x][u.y]==3&&u.f){u.f=u.f;ans=min(ans,u.c);}for(int i=0;i<4;i++){int xx=u.x+dx[i];int yy=u.y+dy[i];if(xx<1||yy<1||xx>n||yy>m||mp[xx][yy]==1)continue;if(mp[xx][yy]==3&&u.f==0)continue;v.x=xx,v.y=yy,v.c=u.c+1,v.f=u.f;if(mp[xx][yy]==4)v.f=1;if(vis[xx][yy][v.f]<=v.c)continue;vis[xx][yy][v.f]=v.c;Q.push(v);}}printf("%d\n",ans);}
0 0
- 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- bzoj 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛 暴力
- bzoj 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- bzoj1669 [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- [BZOJ1669][Usaco2006 Oct]Hungry Cows饥饿的奶牛
- BZOJ1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- BZOJ1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- BZOJ1669 [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- bzoj1669 [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- BZOJ 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛|动态规划
- 【BZOJ】1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛 最长上升子序列
- bzoj1669 [Usaco2006 Oct]Hungry Cows饥饿的奶牛(nlogn求最长不下降子序列)
- bzoj 1667: [Usaco2006 Oct]Cows on Skates滑旱冰的奶牛(BFS)
- P1868 饥饿的奶牛
- 饥饿的奶牛
- P1868 饥饿的奶牛
- [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏 记忆化搜索
- bzoj1666[Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏
- Fragment提交transaction导致state loss异常
- 添加Commons11个jar,就ok
- CentOS7中systemctl的使用
- 《Objective-C 高级编程》读书笔记之 ARC
- IBM老机器的引导盘版本对应
- 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛
- 1的个数
- Apache Tiles的基本使用
- HTML5教程-CSS基础-清除浮动-李南江
- 关于ORACLE游标的问题(ORA-01000: maximum open cursors exceeded)
- [已解决]android的textview 里面的text 怎么也不到中间的位置,这个时候需要设置android:includeFontPadding="false"
- ActiveMQ应用详解
- 《Objective-C 高级编程》读书笔记之 Blocks
- 网易视频云:分布式视频处理集群中的作业调度