https://www.cometoj.com/contest/58/problem/C?problem_id=2760
思路:手动模拟发现无论从哪里开始结果一样;
dp[i][j][k]表示第i个元组j(0/1)变不变化,k表示变化的连续段次数(0/1);
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std;
#define sfi(x) scanf("%d",&x)
#define sfc(x) scanf("%c",x)
#define sfl(x) scanf("%lld",&x)
#define sfs(x) scanf("%s",x)
#define rint register int
#define pb push_back
#define fl() printf("flag!\n")
#define INF 0x3f3f3f3f
#define ll long long
#define mem(x,y) memset(x,y,sizeof(x))
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const int maxn=1e6+9;
ll dp[maxn][2][2],a[maxn],b[maxn];
int main()
{
//FAST_IO;
//freopen("input.txt","r",stdin);
int n,k;
cin>>n>>k;
mem(dp,INF);
for(int i=1;i<=n;i++)
{
cin>>a[i]>>b[i];
}
dp[1][0][0]=0;
dp[1][1][1]=0;
for(int i=2;i<=n;i++)
{
dp[i][0][0]=dp[i-1][0][0]+a[i]*b[i-1];
dp[i][1][1]=min(dp[i-1][0][0]+k*a[i]*b[i-1],dp[i-1][1][1]+(k*a[i])*(k*b[i-1]));
dp[i][0][1]=min(dp[i-1][0][1]+a[i]*b[i-1],dp[i-1][1][1]+(a[i])*(k*b[i-1]));
}
cout<<min(dp[n][0][0],min(dp[n][1][1],dp[n][0][1]))<<endl;
return 0;
}