#include #include #include #define rep(i,a,b) for(i=a;i*(int*)b){ return 1; }else if(*(int*)a <*(int*)b){ return -1; }else{ return 0; } } int main(void){ int d,i,j,kk=0,ma,mb,p; int mini=1000,k=0,qi=0,qj=0,n; int s=0,h=0; int a[5010],b[5010],c[5010],w=0; int heavy=1e9; int x_size = 1; // 1次元のサイズ int y_size = 5010; // 2次元のサイズ int z_size = 15010; // 3次元のサイズ // 三次元配列の動的確保 int ***dp; dp = (int ***)malloc(x_size * sizeof(int**)); for (int i = 0; i < x_size; ++i) { dp[i] = (int **)malloc(y_size * sizeof(int*)); for (int j = 0; j < y_size; ++j) { dp[i][j] = (int *)malloc(z_size * sizeof(int)); } } scanf("%d%d",&n,&p); rep(i,1,n+1){ scanf("%d%d%d",&a[i],&b[i],&c[i]); } rep(i,0,n+1){ rep(j,0,15001){ dp[0][i][j]=heavy; } } rep(i,0,4){ dp[0][0][i]=0; } rep(i,1,n+1){ rep(j,0,i*3+1){ if(j==0){ dp[0][i][0]=dp[0][i-1][0]+a[i]; } if(j==1){ dp[0][i][1]=fmin(dp[0][i-1][1]+a[i],dp[0][i-1][0]+b[i]); } if(j==2){ dp[0][i][2]=fmin(dp[0][i-1][0]+c[i],dp[0][i-1][1]+b[i]); dp[0][i][2]=fmin(dp[0][i][2],dp[0][i-1][2]+a[i]); } if(j==3){ dp[0][i][3]=fmin(dp[0][i-1][0]+1,dp[0][i-1][1]+c[i]); dp[0][i][3]=fmin(dp[0][i][3],dp[0][i-1][2]+b[i]); dp[0][i][3]=fmin(dp[0][i][3],dp[0][i-1][3]+a[i]); } if(j>=4){ dp[0][i][j]=fmin(dp[0][i-1][j-1]+b[i],dp[0][i-1][j-2]+c[i]); dp[0][i][j]=fmin(dp[0][i][j],dp[0][i-1][j-3]+1); dp[0][i][j]=fmin(dp[0][i][j],dp[0][i-1][j]+a[i]); } } } double sss=0.0; sss=(double)dp[0][n][p]/n; printf("%lf\n",sss); free(dp); }