×

spoj PIGBANK TLE even though i am using DP

 0 #include using namespace std; //typedef long long int lint;` define INF 1000000000 int dp[10001]; int coins(int wt,int a[],int v[],int n) { if(wt<0) return INF; if(wt==0) return 0; if(dp[wt]!=INF) return dp[wt]; for(int i=0;i>t; while(t--) { int e,f; cin>>e>>f; int wt=f-e; for(int i=0;i>n; int a[n],v[n]; for(int i=0;i>v[i]>>a[i]; int m=coins(wt,a,v,n); if(m==INF) cout<<"This is impossible.\n"; else cout<<"The minimum amount of money in the piggy-bank is "<

 0 Here is My AC solution to this problem. I have coded it very simple so that you can understand every part of it. Have a look it might help you in figuring out your mistake . http://ideone.com/wALGfV answered 04 Jan '15, 22:18 1.7k●1●17●30 accept rate: 11% thanks for the reply.I see you have used bottom-up approach .I converted my top-down approach to bottom up it got accepted.Does anyone know why? (06 Jan '15, 18:20)
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×2,172

question asked: 04 Jan '15, 19:53

question was seen: 1,474 times

last updated: 06 Jan '15, 18:20