Hello Yarin, You told that you had tested my solution. But After changing the limit I got 504 for your inout. So, there be aything wrong. Please help.

Moderator: Board moderators
so you can calculate the rest of coins as followYou may assume that the machine won't run out of coins and that I always have enough coins to buy all the cokes I want.
Code: Select all
ones_left = original_money - 8*cokes_bought - 5*fives_left - 10*tens_left
Code: Select all
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
int dpp[151][101][51],used[151][101][51],cct,t,C,N1,N5,N10,M;
int dp(int c,int n5,int n10)
{
int n1=M-(C-c)*8-n5*5-n10*10;
if (n1<0||n5<0||n10<0) return 202364231;
if (c==0)return dpp[c][n5][n10]=0;
if (used[c][n5][n10]==cct)return dpp[c][n5][n10];
used[c][n5][n10]=cct;
int a=202364231;
if(n1>=8)a<?=dp(c-1,n5,n10)+8;
if(n1>=3&&n5>=1)a<?=dp(c-1,n5-1,n10)+4;
if(n10>=1)a<?=dp(c-1,n5,n10-1)+1;
if(n5>=2)a<?=dp(c-1,n5-2,n10)+2;
if(n10>=1&&n1>=3)a<?=dp(c-1,n5+1,n10-1)+4;
return dpp[c][n5][n10]=a;
}
int main()
{
freopen("1.txt","r",stdin);
freopen("2.txt","w",stdout);
scanf("%d\n",&t);
memset(dpp,-1,sizeof(dpp));memset(used,-1,sizeof(dpp));
while (t--)
{
cct=-10*(t+5);
scanf("%d %d %d %d\n",&C,&N1,&N5,&N10);
M=N1+N5*5+N10*10;
int ans=202364231;
if(N1>=8)ans<?=dp(C-1,N5,N10)+8;
if(N1>=3&&N5>=1)ans<?=dp(C-1,N5-1,N10)+4;
if(N10>=1)ans<?=dp(C-1,N5,N10-1)+1;
if(N5>=2)ans<?=dp(C-1,N5-2,N10)+2;
if(N10>=1&&N1>=3)ans<?=dp(C-1,N5+1,N10-1)+4;
printf("%d\n",ans);
}
return 0;
}