时光包裹=》2020.11.6

· · 个人记录

今天卡了n小时

为甚么这样子做是错的

我只是每次都记录时间而已

虽然傻了点但不应该错啊

发送时光包裹

一年后再来研究这题

题目

过不了的数据

16 10
2 30
3 100
4 20
6 50
7 60
8 10
9 100
10 20
12 20
13 20
15 20
17 100
18 80
20 100
24 10
25 60
#include<bits/stdc++.h>
using namespace std;
long long  f[55][55][5];//0=>xtime 1=>ytime 2=>xpos's min 3=>ypos
int n,c;
int a[55],p[55];
int sum[55];
int main()
{
 #ifndef ONLINE_JUDGE
    freopen("cin.txt","r",stdin);
//  freopen("cout.txt","w",stdout);
    #endif
    cin>>n>>c;
    for(int i=1;i<=n;i++)
    {
        scanf("%d %d",&a[i],&p[i]);
        sum[i]+=sum[i-1]+p[i];
    }
    memset(f,0x3f,sizeof(f));
        //      printf("f[3][4][0]=%lld\n",f[3][4][0]);

    f[c][c][0]=0;
    f[c][c][1]=0;
    f[c][c][2]=0;
    f[c][c][3]=0;//0=>xtime 1=>ytime 2=>xpos's min 3=>ypos
    for(int len=2;len<=n;len++)
    {
        int i=c-len+1,j;
        if(i<1)i=1;
        //i=1;
        for(;(j=i+len-1)<=n;i++)
        {
            //deal x  tx1 stand for left block cost's time ´¦Àí×îºóÍ£ÔÚ×ó±ßµÄÇé¿ö 
            int tx,ty,mark1=1,mark2=1;
            tx=a[i+1]-a[i]+f[i+1][j][0];
            ty=a[j]-a[i]+f[i+1][j][1];
            //0=>xtime 1=>ytime 2=>xpos's min 3=>ypos
            //f[i][j][0]  ×îºóÍ£ÔÚ×ó±ßµÄºÄʱ
            //f[i][j][1]  ×îºóÍ£ÔÚÓұߵĺÄʱ
            //f[i][j][2]  ×îºóÍ£ÔÚ×ó±ßµÄ´ð°¸ 
            //f[i][j][3]  ×îºóÍ£ÔÚÓұߵĴ𰸠
    //      if(i==2&&j==4)
    //      {
        //  printf("f[%d][%d][0]=%lld a[%d]=%d a[%d]=%d\n",i,j-1,f[i][j-1][0],j,a[j],j-1,a[j-1]);
        //  printf("tx=%d ty=%d\n",tx,ty);//if(ty<0x3f3f3f3f)printf("ok\n");

    //      }




            //
            if(tx<0x3f3f3f3f&&f[i+1][j][2]+tx*p[i]<=f[i][j][2])
            {
                mark1=0;
                f[i][j][2]=f[i+1][j][2]+tx*p[i];

                f[i][j][0]=tx;
        //          if(i==3&&j==4)printf("\n-------------\n");

            }
        ///         printf("len=%d i=%d j=%d ans2=%lld t2=%lld ans3=%lld t3=%lld\n",len,i,j,f[i][j][2],f[i][j][0],f[i][j][3],f[i][j][1]) ;

            //
            if(ty<0x3f3f3f3f&&f[i+1][j][3]+ty*p[i]<=f[i][j][2]||(f[i+1][j][3]+ty*p[i]==f[i][j][2]&&f[i][j][0]>ty))
            {
                mark1=0;
                f[i][j][2]=f[i+1][j][3]+ty*p[i];
        //      if(i==3&&j==4)printf("\n-------------\n");
        //          if(i==2&&j==4)
        //      {
        //          printf("\n++ f[%d][%d][3]=%lld ty=%d p[%d]=%d\n",i+1,j,f[i+1][j][3],ty,i,p[i]);
        //      }
        //                  printf("len=%d i=%d j=%d ans2=%lld t2=%lld ans3=%lld t3=%lld\n",len,i,j,f[i][j][2],f[i][j][0],f[i][j][3],f[i][j][1]) ;

                f[i][j][0]=ty;
            }


            //f[i][j][0]  ×îºóÍ£ÔÚ×ó±ßµÄºÄʱ
            //f[i][j][1]  ×îºóÍ£ÔÚÓұߵĺÄʱ
            //f[i][j][2]  ×îºóÍ£ÔÚ×ó±ßµÄ´ð°¸ 
            //f[i][j][3]  ×îºóÍ£ÔÚÓұߵĴ𰸠
            //deal with y  ´¦Àí×îºóÍ£ÔÚÓұߵÄÇé¿ö           

            tx=a[j]-a[i]+f[i][j-1][0];//Í£ÔÚ×ó±ßµÄλÖÃÔÙÅܵ½j 
            ty=a[j]-a[j-1]+f[i][j-1][1];
//
            if(tx<0x3f3f3f3f&&f[i][j-1][2]+tx*p[j]<=f[i][j][3])
            {
                mark2=0;
                f[i][j][3]=f[i][j-1][2]+tx*p[j];
                f[i][j][1]=tx;
            }
            //
            if(ty<0x3f3f3f3f&&f[i][j-1][3]+ty*p[j]<f[i][j][3]||(f[i][j-1][3]+ty*p[j]==f[i][j][3]&&f[i][j][1]>ty))
            {
            //  if()
               mark2=0;
                f[i][j][3]=f[i][j-1][3]+ty*p[j];
                f[i][j][1]=ty;
            }



            if(mark2==1)
            {
                if(mark1==1)continue;
                f[i][j][3]=f[i][j][2];
                f[i][j][1]=f[i][j][0]+a[j]-a[i];
            }else
            {
                if(mark1==1)
                {
                f[i][j][2]=f[i][j][3];
                f[i][j][0]=f[i][j][1]+a[j]-a[i];                    
                }

            }

            int k=sum[n]-sum[j]+sum[i-1]; 
            k=0;

            printf("len=%d i=%d j=%d ans2=%lld t2=%lld ans3=%lld t3=%lld\n",len,i,j,f[i][j][2]+k*f[i][j][0],f[i][j][0],f[i][j][3]+k*f[i][j][1],f[i][j][1]) ;

        }


    }

    printf("%lld\n",min(f[1][n][2],f[1][n][3])) ;
}