ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1000. A+B Problem

Solve it with dp
Posted by gnaggnoyil 6 Oct 2009 07:06
 var a,b,i,j:longint;
       f:array[0..maxlongint,0..maxlongint] of longint;
 function max(a,b:longint):longint;
 begin
   if a>b then exit(a) else exit(b);
 end;
 begin
    readln(a,b);
    for i:=1 to a do
     for j:=1 to b do
      f[i,j]:=max(f[i-1,j],f[i,j-1])+1;
    writeln(f[a,b]);
 end.
Re: Solve it with dp
Posted by Tbilisi SU: Giorgi Saghinadze (GVS) 6 Oct 2009 18:11
nice solution :D
another solution with recursion

#include <iostream>

using namespace std;

int add(int a , int b)
{
    if (a <= 1 && b <= 1)
       return a + b;

    return add(a / 2 , b / 2) + add(a / 2, b / 2) + (b % 2) + (a % 2);
}
int main()
{
    int a , b;
    cin>>a>>b;
    cout<<add(a,b)<<endl;
    return 0;
}
Re: Solve it with dp
Posted by Oleg Strekalovsky aka OSt [Vologda SPU] 6 Oct 2009 20:59
Are your shure, that it is Problem № 1000 ?
Re: Solve it with dp
Posted by Alex Tolstov for Rybinsk 2009 6 Oct 2009 21:01
O_o