You are not logged in. Please login at www.codechef.com to post your questions!

×

SUMTHING INOI PRACTICE SERVER

i have attached my code for sumthing. i am getting 30/100. please find errors.

#include<iostream>

 #include<vector>
#include<string>
 #include<math.h>
 #include<algorithm>

using namespace std;

int n;long long int t;int tab[55][100005];string arr;

vector <int> v;

int dp(int endnum,long long int val)

{

   if(!endnum)

   {

        if(val==v[0]) return 0;

          else

        return -1;

  }

 int vs=55;

 if(tab[endnum][val]>=0)

   return tab[endnum][val];

   for(int j=endnum-1;j>=-1;j--)

    {

           long long int sub=0;

            for(int k=endnum;k>=j+1;k--) sub+=(v[k]*pow(10,endnum-k));

            long long int pass=val-sub;

            if(pass>=0&&j!=-1)

            {

                    if(tab[j][pass]>=0) return tab[j][pass];

                      tab[j][pass]=1+dp(j,pass);

                     vs=min(vs,tab[j][pass]);

              }

             else if(j==-1&&pass>=0)

             {

                      if(sub==val)

                       return 0;

                       else

                        return -1;

               }

                 else

                 break;

       }

      if(vs>n)

        return -1;

        tab[endnum][val]=vs;

         return vs;

}

int main() {

ios::sync_with_stdio(0);
cin>>n;
cin>>arr;
cin>>t;
for(int i=0;i<55;++i)
    for(int j=0;j<100004;++j)
    tab[i][j]=-1;
for(int i=0;i<n;++i) v.push_back(arr[i]-'0');
int ans=dp(n-1,t);
if(ans<=0) cout<<-1;
else cout<<ans;
return 0;

}

asked 25 Jan '15, 17:43

a1a99_3's gravatar image

6★a1a99_3
6113
accept rate: 16%


I am getting 30/100 too. I don't think my solution is wrong. Did anyone get 100/100?

link

answered 27 Jan '15, 14:56

ketanhwr's gravatar image

6★ketanhwr
1.9k31844
accept rate: 15%

edited 27 Jan '15, 14:56

Yeah. I don't remember what I did though. I think it was something like knapsack, but not sure

http://paste.ubuntu.com/9895423/

If you aren't able to get it I'll try to look through and recollect

(27 Jan '15, 15:07) superty3★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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,020

question asked: 25 Jan '15, 17:43

question was seen: 2,717 times

last updated: 27 Jan '15, 15:08