×

# Code giving WA on c++(gcc 4.8.1) but getting accepted on c++(gcc 4.3.2)?

 0 Here is the problem that I am attempting: http://www.codechef.com/problems/PPTEST A simple knapsack problem solved using DP. Here is the code that is getting accepted when I choose C++(gcc 4.3.2) as my language but giving WA for C++(gcc 4.8.1). Can somebody help me figure it out what could it be because of? #include #include using namespace std; #define MAXN 100 int c[MAXN],p[MAXN],t[MAXN],dp[MAXN+1]={0}; int max(int a,int b) { if(a>b)return a; else return b; } int main() { int te; scanf("%d",&te); while(te--) { int n,w; scanf("%d%d",&n,&w); for(int i=0;i<=w;i++)dp[i]=0; for(int i=0;i=0;j--) dp[t[i]+j]=max(dp[j]+c[i],dp[t[i]+j]); int ans=0; for(int i=0;i<=w;i++) ans=max(ans,dp[i]); printf("%d\n",ans); } }  This question is marked "community wiki". asked 21 Oct '13, 03:25 46●1●1●5 accept rate: 0% 4.2k●5●23●64

 0 you have problems in setting max size of dp array. Note that t[i] + j can go greater than MAX (100 in your case) that will make problems answered 21 Oct '13, 04:17 2.5k●52●135●169 accept rate: 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:

×24
×8

question asked: 21 Oct '13, 03:25

question was seen: 1,218 times

last updated: 21 Oct '13, 04:17