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

gnaggnoyil Solve it with dp [3] // Problem 1000. A+B Problem 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.
Freeuni: GioSag Re: Solve it with dp [2] // Problem 1000. A+B Problem 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;
}
Oleg Strekalovsky [Retired] Re: Solve it with dp [1] // Problem 1000. A+B Problem 6 Oct 2009 20:59
Are your shure, that it is Problem № 1000 ?
Alex Tolstov for Rybinsk 2009 Re: Solve it with dp // Problem 1000. A+B Problem 6 Oct 2009 21:01
O_o