BZOJ 4993: [Usaco2017 Feb]Why Did the Cow Cross the Road II LCS
来源:互联网 发布:ubuntu查找java路径 编辑:程序博客网 时间:2024/06/08 16:19
4993: [Usaco2017 Feb]Why Did the Cow Cross the Road II
Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 28 Solved: 19
[Submit][Status][Discuss]
Description
上下有两个长度为n、位置对应的序列A、B,
其中数的范围均为1~n。若abs(A[i]-B[j])<= 4,则A[i]与B[j]间可以连一条边。
现要求在边与边不相交的情况下的最大的连边数量。
n <= 10^3
Input
Output
Sample Input
6
1
2
3
4
5
6
6
5
4
3
2
1
1
2
3
4
5
6
6
5
4
3
2
1
Sample Output
5
裸LCS
刷水有益健康
#include<cmath>#include<ctime>#include<cstdio>#include<cstring>#include<cstdlib>#include<iostream>#include<algorithm>#include<iomanip>#include<vector>#include<string>#include<bitset>#include<queue>#include<set>#include<map>using namespace std;typedef long long ll;inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}return x*f;}void print(int x){if(x<0)x=-x,putchar('-');if(x>=10)print(x/10);putchar(x%10+'0');}int n,x[1007],y[1007],dp[1007][1007];int main() { n=read();for(int i=1 ; i<=n ; i++) x[i]=read();for(int i=1 ; i<=n ; i++) y[i]=read();for(int i=1 ; i<=n ; i++){for(int j=1 ; j<=n ; j++){if(abs(x[i]-y[j]) <= 4) dp[i][j] = dp[i-1][j-1]+1;else dp[i][j] = max(dp[i][j-1],dp[i-1][j]);}}cout << dp[n][n] << '\n'; return 0;}
阅读全文
0 0
- BZOJ 4993: [Usaco2017 Feb]Why Did the Cow Cross the Road II LCS
- BZOJ 4990: [Usaco2017 Feb]Why Did the Cow Cross the Road II 树状数组优化LCS
- bzoj 4993: [Usaco2017 Feb]Why Did the Cow Cross the Road II
- [Usaco2017 Feb]Why Did the Cow Cross the Road II
- bzoj 4990: [Usaco2017 Feb]Why Did the Cow Cross the Road II
- bzoj 4996: [Usaco2017 Feb]Why Did the Cow Cross the Road II
- 4992: [Usaco2017 Feb]Why Did the Cow Cross the Road
- bzoj4995: [Usaco2017 Feb]Why Did the Cow Cross the Road
- bzoj4989: [Usaco2017 Feb]Why Did the Cow Cross the Road
- Bzoj4989 [Usaco2017 Feb]Why Did the Cow Cross the Road
- [Usaco2017 Feb]Why Did the Cow Cross the Road
- [Usaco2017 Feb]Why Did the Cow Cross the Road III
- BZOJ 4989: [Usaco2017 Feb]Why Did the Cow Cross the Road 逆序对
- bzoj 4994: [Usaco2017 Feb]Why Did the Cow Cross the Road III
- bzoj 4995: [Usaco2017 Feb]Why Did the Cow Cross the Road
- bzoj 4989: [Usaco2017 Feb]Why Did the Cow Cross the Road
- bzoj 4997: [Usaco2017 Feb]Why Did the Cow Cross the Road III
- bzoj 4991: [Usaco2017 Feb]Why Did the Cow Cross the Road III
- JSON数据解析生成一个每行10列,行数不固定的表格
- 使用Eclipse 导出jar包,同时将额外的jar加入一起导出
- 多人邮箱发送
- JS与JSP区别
- $.parseJSON
- BZOJ 4993: [Usaco2017 Feb]Why Did the Cow Cross the Road II LCS
- SpringMVC@ModelAttribute的运行流程
- C语言中的宏
- 前端实战小技巧
- OAI搭建教程
- 怎样设置ABBYY PDF Transformer+中PDF转换
- 怎样变得成熟?
- 插入排序
- Linux中ELF格式文件介绍