bzoj1996 [Hnoi2010]chorus 合唱队
2017-03-24 20:15
218 查看
Description
Input
Output
Sample Input
41701 1702 1703 1704
Sample Output
8HINT
正解:区间$DP$。
比较简单的区间$DP$,但是因为是$HNOI$所以必须留版面。。
设$f[0][l][r]$表示已经处理完区间$l,r$之间的人,最后一个人放在左边的方案数,$f[1][l][r]$表示已经处理完区间$l,r$之间的人,最后一个人放在右边的方案数。然后直接大力转移就行了。
//It is made by wfj_2048~ #include <algorithm> #include <iostream> #include <cstring> #include <cstdlib> #include <cstdio> #include <vector> #include <cmath> #include <queue> #include <stack> #include <map> #include <set> #define inf (1<<30) #define il inline #define RG register #define ll long long #define rhl (19650827) using namespace std; ll f[2][1010][1010],a[1010],n; il int gi(){ RG int x=0,q=1; RG char ch=getchar(); while ((ch<'0' || ch>'9') && ch!='-') ch=getchar(); if (ch=='-') q=-1,ch=getchar(); while (ch>='0' && ch<='9') x=x*10+ch-48,ch=getchar(); return q*x; } il void work(){ n=gi(),a[0]=inf; for (RG int i=1;i<=n;++i) a[i]=gi(),f[0][i][i]=f[1][i][i]=1,f[0][i-1][i]=f[1][i-1][i]=(a[i-1]<a[i]); for (RG int k=3;k<=n;++k) for (RG int l=1;l+k-1<=n;++l){ RG int r=l+k-1; f[0][l][r]=(a[l]<a[l+1])*f[0][l+1][r]+(a[l]<a[r])*f[1][l+1][r]; f[1][l][r]=(a[l]<a[r])*f[0][l][r-1]+(a[r-1]<a[r])*f[1][l][r-1]; if (f[0][l][r]>=rhl) f[0][l][r]-=rhl; if (f[1][l][r]>=rhl) f[1][l][r]-=rhl; } printf("%lld\n",(f[0][1] +f[1][1] )%rhl); return; } int main(){ work(); return 0; }
相关文章推荐
- [BZOJ1996][Hnoi2010]chorus 合唱队
- bzoj千题计划211:bzoj1996: [Hnoi2010]chorus 合唱队
- BZOJ 1996: [Hnoi2010]chorus 合唱队
- 1996: [Hnoi2010]chorus 合唱队 - BZOJ
- BZOJ1996 [Hnoi2010]chorus 合唱队
- bzoj1996: [Hnoi2010]chorus 合唱队
- bzoj1996【HNOI2010】chorus 合唱队
- bzoj1996: [Hnoi2010]chorus 合唱队
- BZOJ 1996: [Hnoi2010]chorus 合唱队 区间dp
- bzoj 1996: [Hnoi2010]chorus 合唱队
- 【bzoj1996】[Hnoi2010]chorus 合唱队 区间dp
- bzoj 1996: [Hnoi2010]chorus 合唱队
- [bzoj 1996] [Hnoi2010]chorus 合唱队
- 【BZOJ1996】[Hnoi2010]chorus 合唱队 区间DP
- 【BZOJ1996】[Hnoi2010]chorus 合唱队【区间DP】
- [BZOJ]1996: [Hnoi2010]chorus 合唱队 区间DP
- BZOJ1996: [Hnoi2010]chorus 合唱队|动态规划
- 【BZOJ1996】【Hnoi2010】chorus 合唱队 动态规划
- 【BZOJ 1996】 [Hnoi2010]chorus 合唱队
- BZOJ 1996: [Hnoi2010]chorus 合唱队(dp)