|
|
вернуться в форумSolve it with dp 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 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 Are your shure, that it is Problem № 1000 ? |
|
|