#include <iostream>#include <sstream>#include <vector>#include <algorithm>#include <limits>#include <cassert>#define REP(i, b, e) for (size_t i = b; i < e; ++i)#define REPE(i, b, e) for (size_t i = b; i <= e; ++i)voidfill(std::vector<long>&v,longvalue){std::fill(v.begin(),v.end(),value);}intmain(){constsize_tmax_x=1000;std::strings;std::getline(std::cin,s);size_tn,m;std::istringstream(s)>>n>>m;assert(2<=n&&n<=150);assert(m<=(n+1)/2);std::vector<std::vector<long>>slip(n+3,std::vector<long>(max_x,-1));// -1 means there is no stonefill(slip[0],0);// start shore (0 is dummy value)fill(slip[n+1],0);// goal shore (0 is dummy value)fill(slip[n+2],0);// goal shore (0 is dummy value)REPE(y,1,n){std::getline(std::cin,s);std::istringstreamsin(s);size_tk;sin>>k;assert(k<=10);for(;k;--k){size_tx;longd;sin>>x>>d;assert(1<=x&&x<=max_x);assert(1<=d&&d<=1000);--x;// now starts with 0 not 1slip[y][x]=d;}}std::vector<std::vector<std::vector<long>>>dp(n+3,std::vector<std::vector<long>>(max_x,std::vector<long>(m+1,std::numeric_limits<long>::max())));dp.front().swap(std::vector<std::vector<long>>(max_x,std::vector<long>(m+1,0)));REPE(y1,0,n)REP(x1,0,max_x)if(slip[y1][x1]>=0)// source{REPE(y2,y1+1,y1+2)REP(x2,0,max_x)if(slip[y2][x2]>=0)// destinition{constsize_tnow_jumped=y2-y1-1;assert(now_jumped==0||now_jumped==1);for(size_told_jumped=0;old_jumped+now_jumped<=m;++old_jumped){if(dp[y1][x1][old_jumped]!=std::numeric_limits<long>::max()){long&src=dp[y1][x1][old_jumped];long&dst=dp[y2][x2][old_jumped+now_jumped];dst=std::min(dst,src+(slip[y1][x1]+slip[y2][x2])*long(x2>x1?x2-x1:x1-x2));}}}}longresult=std::numeric_limits<long>::max();REPE(y,n+1,n+2)REP(x,0,max_x)REPE(jumped,0,m)// goal shore{result=std::min(result,dp[y][x][jumped]);}std::cout<<result<<std::endl;}
ocean
#6316()
[
C++
]
Rating0/0=0.00
Rating0/0=0.00-0+
1 reply [ reply ]