# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
199459 | TadijaSebez | Jump (BOI06_jump) | C++11 | 27 ms | 5624 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N=105;
int a[N][N],n,m;
bool was[N][N];
struct Number
{
int c[N];
void init(){ for(int i=0;i<N;i++) c[i]=0;}
Number(){ init();}
void push(){ for(int i=0;i<N-1;i++) c[i+1]+=c[i]/10,c[i]%=10;}
Number(int x){ init();c[0]=x;push();}
void print()
{
int ptr=N-1;
while(ptr>0 && c[ptr]==0) ptr--;
for(int i=ptr;i>=0;i--) printf("%i",c[i]);
printf("\n");
}
};
Number operator + (Number a, Number b)
{
Number ans;
for(int i=0;i<N;i++) ans.c[i]=a.c[i]+b.c[i];
ans.push();
return ans;
}
Number dp[N][N];
Number DP(int x, int y)
{
if(x==n && y==m) return Number(1);
if(was[x][y]) return dp[x][y];
was[x][y]=1;
if(a[x][y]==0) return dp[x][y]=Number(0);
dp[x][y].init();
if(x+a[x][y]<=n) dp[x][y]=dp[x][y]+DP(x+a[x][y],y);
if(y+a[x][y]<=m) dp[x][y]=dp[x][y]+DP(x,y+a[x][y]);
//printf("%i %i: ",x,y);
//dp[x][y].print();
return dp[x][y];
}
int main()
{
scanf("%i",&n);
m=n;
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%i",&a[i][j]);
DP(1,1).print();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |