9 20

  The subject of the quality okay mistake: still not thinking clearly began to write the code to waste some time. Advantages: no hand lazy to write a pat on the kind of feeling is very stable.

Obviously even number 0 found even bit odd considering the cost is negative then found feasible because the odd bit numbers for each position is> 0, the answer is an odd bit in the min-1

#//#include<bits/stdc++.h>
#include<iostream>
#include<queue>
#include<iomanip>
#include<cctype>
#include<cstdio>
#include<deque>
#include<utility>
#include<cmath>
#include<ctime>
#include<cstring>
#include<string>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
#define INF 1000000000
#define ll long long
#define db double
#define pb push_back
#define un unsigned
using namespace std;
char *ft,*fs,buf[1<<15];
inline char getc()
{
    return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))?0:*fs++;
}
inline int read()
{
    int x=0,f=1;char ch=getc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getc();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getc();}
    return x*f;
}
const int MAXN=2010;
int n;
int minn=INF,ans;
int a[MAXN];
int b[MAXN];
int main()
{
    //freopen("1.in","r",stdin);
    freopen("thief.in","r",stdin); 
    freopen("thief.out","w",stdout);
    n=read();
    for(int i=1;i<=n;++i)a[i]=read();
    if(n&1)
    {
        for(int i=1;i<=n;++i)
            if(i&1)minn=min(minn,a[i]-1);
        /*for(int i=1;i<=n;++i)
        {
            if(i&1)b[i]=a[i]-minn;
            else b[i]=a[i]+minn;
            ans+=a[i]-b[i];
        }*/
        printf("%d\n",minn);
    }
    else puts("0");
    return 0;
}
/*
#//#include<bits/stdc++.h>
#include<iostream>
#include<queue>
#include<iomanip>
#include<cctype>
#include<cstdio>
#include<deque>
#include<utility>
#include<cmath>
#include<ctime>
#include<cstring>
#include<string>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
#define INF 1000000000
#define ll long long
#define db double
#define pb push_back
#define un unsigned
using namespace std;
char *ft,*fs,buf[1<<15];
inline char getc()
{
    return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))?0:*fs++;
}
inline int read()
{
    int x=0,f=1;char ch=getc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getc();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getc();}
    return x*f;
}
const int MAXN=2010;
int n;
int minn=INF,ans;
int a[MAXN];
int b[MAXN];
inline int check(int x,int w)
{
    b[x]=a[x]-w;
    int j=x-1,s=w;
    while(j)
    {
        b[j]=a[j]+s;
        s=-s;
        if(b[j]<1)return 0;
        --j;
    }
    j=x+1;s=w;
    while(j<=n)
    {
        b[j]=a[j]+s;
        s=-s;
        if(b[j]<1)return 0;
        ++j;
    }
    int cnt=0;
    for(int i=1;i<=n;++i)
        cnt+=a[i]-b[i];
    return cnt==w;
}
inline void dfs()
{
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<a[i];++j)
        {
            if(check(i,j))ans=max(ans,j);
        }
    }
}
int main()
{
    freopen("1.in","r",stdin);
    n=read();
    for(int i=1;i<=n;++i)a[i]=read();
    dfs();
    printf("%d\n",ans);
    return 0;
}
*/ 
View Code

Violence also attached program ...

This question I think for a long, long time to write up a violent or exploring dp not feel very big nature can not do because there is always the first number is the middle of the restrictions.

So greedy difficult to promote local to the global optimal solution so the numbers should be considered on how to meet the requirements for each position? Configuration is provided using bi = ai-i if the numbers on a certain position of this figure is negative then bound to modify.

Then we find ourselves completely to modify a digital no limit to 0 to directly modify certain feasible because it is bound to have vacancies. So we just need to know how many sequences can not move.

So in fact, the longest rise not fall sequences in fact there is a dichotomy optimization click.

//#include<bits/stdc++.h>
#include<iostream>
#include<queue>
#include<iomanip>
#include<cctype>
#include<cstdio>
#include<deque>
#include<utility>
#include<cmath>
#include<ctime>
#include<cstring>
#include<string>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
#define INF 1000000000
#define ll long long
#define db double
#define pb push_back
#define un unsigned
using namespace std;
char *ft,*fs,buf[1<<15];
inline char getc()
{
    return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))?0:*fs++;
}
inline int read()
{
    int x=0,f=1;char ch=getc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getc();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getc();}
    return x*f;
} 
//The numbers in a sequence modified to strictly monotonic increasing sequence clearly configuration title 
const  int MAXN = 50010 , MAXN = 5010 ;
 int T, n-, Top;
 int S [MAXN];
 int A [MAXN], F [MAXN] ; 
inline void Calc ( int X) 
{ 
    int L = . 1 , R & lt = Top;
     the while (L + . 1 < R & lt) 
    { 
        int MID = (L + R & lt) >> . 1 ;
         IF (S [MID]> X) R & lt = MID ;
         the else L = MID; 
    } 
    IF (S [L]> X) S [L] = X;
    else s[r]=x;
}
int main()
{
    freopen("noname.in","r",stdin); 
    freopen("noname.out","w",stdout);
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    T=read();
    while(T--)
    {
        n=read();
        for(int i=1;i<=n;++i)a[i]=read();
        for(int i=1;i<=n;++i)f[i]=a[i]-i;
        s[top=1]=0;
        for(int i=1;i<=n;++i)
        {
            if(f[i]<0)continue;
            if(f[i]>=s[top])s[++top]=f[i];
            else calc(f[i]);
        }
        --top;
        printf("%d\n",n-top);
    }
    return 0;
}
/*
//#include<bits/stdc++.h>
#include<iostream>
#include<queue>
#include<iomanip>
#include<cctype>
#include<cstdio>
#include<deque>
#include<utility>
#include<cmath>
#include<ctime>
#include<cstring>
#include<string>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
#define INF 1000000000
#define ll long long
#define db double
#define pb push_back
unsigned UN #definer",stdin); 
    freopen("noname.out","w",stdout);
using namespace std;
*. ft char, * FS, buf [15 <<. 1]; 
inline char getc () 
{ 
    return (FS. ft == && (. ft = (FS = buf) + fread (buf, 1,1 << 15, stdin), ? == FS. ft)) 0: FS * ++; 
} 
inline int Read () 
{ 
    int X = 0, F =. 1; char CH = getc (); 
    the while (CH < '0' || CH> '. 9') IF {(CH == '-') = F -1; CH = getc ();} 
    the while (CH> = '0' && CH <= '. 9') = {X * X + CH 10-'0 '; getc = CH ();} 
    return the X-* f; 
} 
// a sequence of numbers will be modified to strictly monotonically increasing sequence apparently constructed title 
// but I'm not 
const int MAXN = 50010, MAXN = 5010; 
int T , n-, Top, m, ANS, Maxx; 
int F [MAXN] [MAXN]; 
int A [MAXN], B [MAXN], C [MAXN]; 
int main () 
{ 
    The freopen ( "noname.in", " r ", stdin);
    //freopen("1.in","r",stdin);
    //freopen("1.out","w",stdout);
    T=read();
    while(T--)
    {
        n=read();maxx=0;
        for(int i=1;i<=n;++i)c[i]=a[i]=read(),maxx=max(maxx,a[i]);
        //if(n<=50)
        {
            m=max(n*2,maxx*2);
            for(int i=1;i<=n;++i)
                for(int j=0;j<=m;++j)
                    f[i][j]=INF;
            for(int i=0;i<=m;++i)f[0][i]=0;
            for(int i=1;i<=n;++i)
                for(int j=i;j<=m;++j)
                {
                    for(int k=0;k<j;++k)
                    {
                        f[i][j]=min(f[i][j],f[i-1][k]+(a[i]==j?0:1));
                    }
                }
            ans=INF;
            for(int i=0;i<=m;++i)ans=min(ans,f[n][i]);
            printf("%d\n",ans);
        }
    }
    return 0;
}
*/
View Code

This problem is more clearly floyd the water briefly, then the state is also very good column should be noted that we do not need to record the position of the third waiter because the location is the location of a third waiter.

This question so that you can pass the ...

#//#include<bits/stdc++.h>
#include<iostream>
#include<queue>
#include<iomanip>
#include<cctype>
#include<cstdio>
#include<deque>
#include<utility>
#include<cmath>
#include<ctime>
#include<cstring>
#include<string>
#include<cstdlib>
#include<vector>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
#define INF 1000000000
#define ll long long
#define db double
#define pb push_back
#define un unsigned
using namespace std;
char *ft,*fs,buf[1<<15];
inline char getc()
{
    return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))?0:*fs++;
}
inline int read()
{
    int x=0,f=1;char ch=getc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getc();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getc();}
    return x*f;
} 
Const  Read ();
    int= MAXN 210 , MAXN = 520. ;
 int n-, T, m, ANS, Last;
 int A [MAXN] [MAXN];
 int B [MAXN];
 int F [MAXN] [MAXN] [MAXN]; // F [ i] [j] [k] denotes the i-th task before the waiter and has a minimum cost in j k another staff of the i-th task. 
int main () 
{ 
    // The freopen ( "1.In", "R & lt", stdin); 
    The freopen ( " service.In " , " R & lt " , stdin); 
    The freopen ( " service.out " , " W " , stdout );
        n=read();m=read();
        for(int i=1;i<=n;++i)
            for(int j=1;j<=n;++j)
                a[i][j]=read();
        for(int k=1;k<=n;++k)
            for(int i=1;i<=n;++i)
                for(int j=1;j<=n;++j)
                    a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
        for(int i=1;i<=m;++i)b[i]=read();
        memset(f,0x3f,sizeof(f));
        last=3;f[0][1][2]=0;
        for(int i=1;i<=m;++i)
        {
            //int w=INF;
            for(int j=1;j<=n;++j)//枚举一个服务员的位置
            {
                 For ( int K = . 1 ; K <= n-; K ++) //Enumeration of the position of the other attendant 
                {
                     // first waiter last 
                    F [I] [Last] [K] = min (F [I] [Last] [K], F [I- . 1 ] [J] [K ] + A [J] [B [I]]);
                     // second attendant last 
                    F [I] [J] [last] = min (F [I] [J] [last], F [I- . 1 ] [J] [K] + A [K] [B [I]]);
                     // third staff past 
                    f [i] [j] [ k] = min (f [i] [j] [k] , F [I- . 1 ] [J] [K] + A [Last] [B [I]]);
                     // W = min (W, F [I] [J] [K]); 
                } 
            } 
            // W << endl << COUT; 
            Last = B [I]; 
        }
        ans=INF;
        for(int i=1;i<=n;++i)
            for(int j=1;j<=n;++j)ans=min(ans,f[m][i][j]);
        printf("%d\n",ans);
    }
    return 0;
}
View Code

Child wear green yo I think

Guess you like

Origin www.cnblogs.com/chdy/p/11568767.html