bzoj 4993: [Usaco2017 Feb]Why Did the Cow Cross the Road II
来源:互联网 发布:淘宝开通直通车多少钱 编辑:程序博客网 时间:2024/05/29 02:01
题意:
上下有两个长度为n、位置对应的序列A、B,
其中数的范围均为1~n。若abs(A[i]-B[j])<= 4,则A[i]与B[j]间可以连一条边。
现要求在边与边不相交的情况下的最大的连边数量。
n <= 10^4。
题解:
我太菜了,这种题都wa一次,最近都不知道怎么了TAT
直接dp,f[i][j]表示左列到i,右列到j的最大匹配。
然后f[i][j]=max(f[i][j],max(f[i][j-1],f[i-1][j]))。
code:
#include<cstdio>#include<cstdlib>#include<iostream>#include<cstring>#include<cmath>using namespace std;int f[1010][1010],n;int a[1010],b[1010];int main(){ scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) scanf("%d",&b[i]); for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) if(abs(a[i]-b[j])<=4) f[i][j]=max(f[i][j],f[i-1][j-1]+1); for(int j=2;j<=n;j++) f[i][j]=max(f[i][j],max(f[i][j-1],f[i-1][j])); } printf("%d",f[n][n]);}
阅读全文
1 0
- bzoj 4993: [Usaco2017 Feb]Why Did the Cow Cross the Road II
- BZOJ 4993: [Usaco2017 Feb]Why Did the Cow Cross the Road II LCS
- [Usaco2017 Feb]Why Did the Cow Cross the Road II
- BZOJ 4990: [Usaco2017 Feb]Why Did the Cow Cross the Road II 树状数组优化LCS
- 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
- XML
- servlet生命周期
- CURL使用SSL证书访问HTTPS
- 最长递增子序列问题
- html ifram应用
- bzoj 4993: [Usaco2017 Feb]Why Did the Cow Cross the Road II
- codeforces 841D Leha and another game about graph
- [Leetcode] 99, 114, 117
- Mac OSX系统、Linux、Windows命令行教程
- 知识分子的悲哀
- OkHttp系列之入门篇
- java实现AES加密
- 光学系统解析
- oracle常用sql语句