SPOJ:WA in Mixtures

I’m getting a WA in the mixtures problem even though my question seems to run for all test cases.
I took the test cases present in http://www.spoj.com/forum/viewtopic.php?f=3&t=4007 and my program seems to work fine.Can anyone help me out?


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define ull unsigned long long
vector<int> v;
ull mem[100][100]={0};
ull smoke(int x,int y)
{
    if(mem[x][y]!=0)
        return mem[x][y];
    if(x==y)
        return 0;
    ull ans=99999999;
    int a,b;
    for(int i=x;i<y;i++)
    {
        a=0;
        for(int j=x;j<=i;j++)
            a+=v[j];
        a%=100;

        b=0;
        for(int j=i+1;j<=y;j++) 
        b+=v[j];
        b%=100;

        ans=min(ans,(smoke(x,i)+smoke(i+1,y)+a*b));
    }
    mem[x][y]=ans;
    return ans;
}

int main()
{
    std::ios::sync_with_stdio(false);
    int n;
    while(!cin.eof())
    {
    v.clear();
    for(int i=0;i<100;i++)
        for(int j=i;j<100;j++)
            mem[i][j]=0;
    cin>>n;
    int temp;
    for(int i=0;i<n;i++)
    {
        cin>>temp;
        v.push_back(temp);
    }
    cout<<smoke(0,n-1)<<endl;

    }
}

The method of input here is different -

There will be a number of test cases in the input.

The first line of each test case will contain n,

Usually you may be using

int t,n;
cin>>t;
while(t–){ cin>>n; … } `

But You have to use the following snippet for this-
int n; while( cin>>n ) {//Code}

It is a varient of Matrix Multiplication problem, it is my AC code, http://ideone.com/HCzOzt
I’ve done it using DP with recursion, and I’ll suggest you to think DP problems using recursion first get it AC then move forward to iterative approach, iterative approach is little difficult for beginners, once you start thinking recursively you’ll start learning why and how dp works, then you can move to iterative approach.
Post an ideone link to your code, its difficult to understand you code herein codechef, I’ll try to help you debug your code, better use my code to debu and find why you’re getting it wrong.