zoukankan      html  css  js  c++  java
  • 洛谷P2896 [USACO08FEB]一起吃饭Eating Together

    洛谷P2896 [USACO08FEB]一起吃饭Eating Together

     1 #include <bits/stdc++.h> 
     2 #define For(i,j,k) for(int i=j;i<=k;i++) 
     3 #define LL long long 
     4 using namespace std ; 
     5 
     6 const int N = 30011,inf = 1e9 ; 
     7 int n,ans ; 
     8 int a[N],f[N][4] ; 
     9 
    10 inline int read() 
    11 {
    12     int x = 0 , f = 1 ; 
    13     char ch = getchar() ; 
    14     while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar() ; } 
    15     while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar() ; } 
    16     return x * f ;  
    17 }
    18 
    19 inline void sw() 
    20 {
    21     For(i,1,n/2) swap(a[i],a[n-i+1]) ; 
    22 }
    23 
    24 inline void dp() 
    25 {
    26     memset(f,1,sizeof f) ; 
    27     f[0][1] = 0 ; 
    28     For(i,1,n) 
    29       For(j,1,3) 
    30         For(k,1,j) 
    31             f[i][j] = min(f[i-1][k]+(j!=a[i]),f[i][j]) ; 
    32     ans = min(ans,f[n][1]) ;
    33     ans = min(ans,f[n][2]) ;
    34     ans = min(ans,f[n][3]) ; 
    35 }
    36 
    37 int main() 
    38 {
    39     n = read() ; 
    40     For(i,1,n) a[ i ] = read() ; 
    41     ans = inf ; 
    42     dp() ;  sw() ; dp() ; 
    43     printf("%d
    ",ans) ; 
    44     return 0 ; 
    45 }
  • 相关阅读:
    Tarjan专题
    Catalan数
    状压DP
    威尔逊定理证明:
    【fzoj 2376】「POJ2503」Babelfish
    Android 源码
    Android实现推送方式解决方案
    Android apk 签名
    圆角的实现
    Android 资源
  • 原文地址:https://www.cnblogs.com/third2333/p/7473125.html
Copyright © 2011-2022 走看看