bzoj3357 [Usaco2004]等差数列
来源:互联网 发布:公安大数据分析研判 编辑:程序博客网 时间:2024/06/07 17:06
题目
神奇dp,但是dp数组要用map存一下,好慢呀。。
#include<bits/stdc++.h>#define N 2000 using namespace std;int n,A[N+5],ans;map <int,int> f[N+5];inline char nc(){ static char buf[100000],*p1=buf,*p2=buf; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;}inline int read(){ int x=0,b=1; char c=nc(); for(;!(c<='9'&&c>='0');c=nc())if(c=='-')b=-1; for(;c<='9'&&c>='0';c=nc())x=x*10+c-'0'; return x*b;}inline void write(int x){ if(x==0)putchar('0'); else { char buf[15]; int len=0; if(x<0)putchar('-'),x=-x; while(x)buf[++len]=x%10+'0',x/=10; for(int i=len;i>=1;i--)putchar(buf[i]); } putchar(' ');}int main(){ freopen("in.txt","r",stdin); n=read(); for(int i=1;i<=n;i++)A[i]=read(); if(n==1)return cout<<1,0; for(int i=1;i<=n;i++) for(int j=1;j<i;j++) { f[i][A[j]]=max(f[i][A[j]],2); f[i][A[j]]=max(f[i][A[j]],f[j][A[j]*2-A[i]]+1); ans=max(ans,f[i][A[j]]); } cout<<ans; return 0;}
阅读全文
0 0
- bzoj3357[Usaco2004]等差数列 DP
- 【bzoj3357】[Usaco2004]等差数列
- bzoj3357 [Usaco2004]等差数列
- bzoj 3357: [Usaco2004]等差数列
- 3357: [Usaco2004]等差数列|DP
- 3357: [Usaco2004]等差数列 DP+map
- BZOJ 3357 Usaco2004 等差数列 动态规划
- bzoj 3357: [Usaco2004]等差数列 动态规划
- 等差数列
- 等差数列
- 等差数列
- 等差数列
- 等差数列
- 等差数列
- 等差数列
- 等差数列
- 等差数列
- 等差数列
- 古典密码——vigenre多表代换密码
- 数据库实例:用户登录
- C++内存模型
- 为Mac添加Sublime Text的命令行
- vector构造二维数组
- bzoj3357 [Usaco2004]等差数列
- 结合redis设计与实现的redis源码学习-4-dict(字典)
- 多线程:控制线程
- 五、jQuery中的事件本质
- spoj Query on a tree again(树链剖分)
- LeetCode题目: 25. Reverse Nodes in k-Group
- 数据库实例:mysql与mongo结合用户登录
- Ubuntu android studio 加载 arr
- CentOS上安装redis