WA

P1220 关路灯

……
by BPG_ning @ 2022-09-10 09:40:01


``` #include<cstdio> #include<string> #include<cstring> using namespace std; int max(int a,int b) { return a>b?a:b; } int min(int a,int b) { return a<b?a:b; } inline int read() { int ret=0,f=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') f=-f; for(; c>='0'&&c<='9'; c=getchar()) ret=ret*10+c-'0'; return ret*f; } const int maxn=60; int n,c; int p[maxn],e[maxn],sum[maxn]; int f[maxn][maxn][5]; signed main(void) { n=read(); c=read(); memset(f,127,sizeof(f)); for(int i=1; i<=n; i++) { p[i]=read(); e[i]=read(); sum[i]=sum[i-1]+e[i]; } f[c][c][0]=f[c][c][1]=0; for(int l=2; l<=n; l++) { for(int i=1; i+l-1<=n; i++) { int j=i+l-1; f[i][j][0]=min(f[i+1][j][0]+(p[i+1]-p[i])*(sum[n]+sum[i]-sum[j]),f[i+1][j][1]+(p[j]-p[i])*(sum[n]+sum[i]-sum[j])); f[i][j][1]=min(f[i][j-1][0]+(p[j]-p[i])*(sum[i-1]+sum[n]-sum[j-1]),f[i][j-1][1]+(p[j]-p[j-1])*(sum[i-1]+sum[n]-sum[j-1])); } } int ans=min(f[1][n][0],f[1][n][1]); printf("%d\n",ans); return 0; }
by BPG_ning @ 2022-09-10 09:41:31


@[BPG_ning](/user/551803) 啊喂!下次要at我啊,不然我怎么知道有回复了
by 柠檬布丁吖 @ 2022-09-10 15:02:11


|