HDU 6570 Wave dp

news/2024/10/17 12:22:58/

  

题意:给出一个长度为n的数列  和一个c   数列的所有数都在c范围内

问:  求一个最长子串  满足下列条件:

1 所有奇数位置的数相等

2 所有偶数位置的数相等

3 偶数位置和奇数位置的数不相等

 

比赛的时候枚举c 然后二分查找n    o( c^2 logn ) 780ms

#include<bits/stdc++.h>
using namespace std;
//input by bxd
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repp(i,a,b) for(int i=(a);i>=(b);--i)
#define RI(n) scanf("%d",&(n))
#define RII(n,m) scanf("%d%d",&n,&m)
#define RIII(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define RS(s) scanf("%s",s);
#define ll long long
#define pb push_back
#define inf 0x3f3f3f3f
#define lson l,m,pos<<1
#define rson m+1,r,pos<<1|1
#define CLR(A,v)  memset(A,v,sizeof A)
//
const int N=1e4+5;
const int mod=1e9+7;vector<int>a[105];
vector<int>::iterator it;
int n,m,c,x;
int check(int i,int j)
{if( !a[i].size()||!a[j].size() )return 0;int ans=1;int pos=a[i][0];while(1){it=lower_bound(a[j].begin(),a[j].end(),pos );if(it==a[j].end())return ans;pos=*it;ans++;it=lower_bound(a[i].begin(),a[i].end(),pos );if(it==a[i].end())return ans;pos=*it;ans++;}
}int main()
{while(~RII(n,c)){rep(i,1,n){RI(x);a[x].pb(i);}int ans=0;rep(i,1,c)rep(j,1,c)if(i!=j)ans=max(ans,check(i,j));printf("%d\n",ans);rep(i,1,100)a[i].clear();}return 0;
}
傻逼代码

 

可以dp做    o(nc) 100ms

#include<bits/stdc++.h>
using namespace std;
//input by bxd
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repp(i,a,b) for(int i=(a);i>=(b);--i)
#define RI(n) scanf("%d",&(n))
#define RII(n,m) scanf("%d%d",&n,&m)
#define RIII(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define RS(s) scanf("%s",s)
#define ll long long
#define see(x) (cerr<<(#x)<<'='<<(x)<<endl)
#define pb push_back
#define inf 0x3f3f3f3f
#define CLR(A,v)  memset(A,v,sizeof A)
typedef pair<int,int>pii;
//
const int N=200;
struct node{int ans,now; }dp[N][N];
int n,m,a[100005],c;
int sol()
{rep(i,1,c)rep(j,1,c)dp[i][j].ans=0,dp[i][j].now=i;rep(i,1,n)RI(a[i]);rep(i,1,n){int x=a[i];rep(j,1,c){if(x==j)continue;if(dp[x][j].now==x){dp[x][j].ans++;dp[x][j].now=j; }if(dp[j][x].now==x){dp[j][x].ans++;dp[j][x].now=j; }}}int ans=0;rep(i,1,c)rep(j,1,c)ans=max(ans,dp[i][j].ans);return ans;
}
int main()
{while(~RII(n,c))printf("%d\n",sol());return 0;
}
View Code

 

转载于:https://www.cnblogs.com/bxd123/p/11224259.html


http://www.ppmy.cn/news/178021.html

相关文章

D - Wave HDU - 6570

暴力求解 Avin is studying series. A series is called “wave” if the following conditions are satisfied: It contains at least two elements;All elements at odd positions are the same;All elements at even positions are the same;Elements at odd positions are…

GPT(4kb硬盘) 单硬盘装变色龙、GA-H61MA-D2V、ALC887-VD、HD6570成功驱动经验(转)

GPT(4kb硬盘) 单硬盘装变色龙、GA-H61MA-D2V、ALC887-VD、HD6570成功驱动经验 2012-08-21 11:32:17 分类&#xff1a; 系统运维 终于用上黑苹果了&#xff0c;所以决定把这近一个月付出辛劳总结归纳一下&#xff0c;以后也记得操作步骤。基础的就不会详细写&#xff0c;要注意或…

MT6570_MT6580参考设计资料介绍

MT6570_MT6580参考设计资料介绍&#xff1a; MT6570_MT6580 Introduction ▪ GPIO and IO application ▪ System dependent design ▪ Power introduction Function design notice ▪ SIM design note (3/4-SIM application) ▪ NAND flash design note ▪ SD/eMMC design not…

HDU - 6570

题目链接&#xff1a;HDU - 6570 暴力的话就是枚举两种颜色&#xff0c;然后暴力求。因为不可能每一种情况都跑满&#xff0c;均摊下来感觉复杂度是&#xff1a;O(ccsqrt(n))。 事实上我们可以O(n*c)dp&#xff0c;令dp[i][j][k] 为&#xff1a;第i项为k&#xff0c;前面的一个…

AMD显卡更新UEFI GOP

一、简介 很多老版本显卡vBIOS仅支持leagcy&#xff0c;所以在UEFI版本的BIOS下不能显示&#xff0c;本文以HD6570其中一款显卡进行操作。 二、操作步骤 2.1 操作环境 windows操作系统GPU-Z 下载地址NV或者AMD显卡BIOS的刷新工具NVFlash或者ATIFlash下载地址制作给显卡BIOS…

MT6572/MT6570芯片资料介绍,MT6572+MT6570处理器

MT6572处理器&#xff1a; 联发科MT6572 可在不损电池使用时间的情况下&#xff0c;为入门级智能型手机提供双核心效能表现。它配备节能的双核心ARM Cortex-A7 处理器&#xff0c;并采用优化了成本效益的系统级设计&#xff0c;简化了产品研发工序&#xff0c;从而降低生产成本…

3D建模新手入门到高端 电脑配置一览

入门机&#xff1a;1000元到3500元中端主流机&#xff1a;4000元到6000元高端机&#xff1a;6000元到10000元 1、1550元方案 方案说明 AMD3200G的CPU性能接近i3 9100F&#xff0c;不过核显是强大的Vega 8&#xff0c;核心频率达到1250MHz&#xff0c;可媲美入门独立显卡&…

黑苹果安装教程「笔记本」「台式机」通用

黑苹果安装教程「笔记本」「台式机」通用