#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#define endl '\n'
#define int long long
string add(string a, string b)
{
if(sz(a)<sz(b)) swap(a,b);
// cout << "here: " << a << " " << b << endl << flush;
if(b.empty()) return a;
int rem=0;
string ans="";
int j=sz(a)-1;
for(int i = sz(b)-1;i >= 0;i--)
{
int x=b[i]-'0'+a[j]-'0'+rem;
if(x>=10) rem=(x-(x%10))/10;
else rem=0;
ans+=(x%10)+'0';
j--;
}
while(j>=0)
{
int x=a[j-sz(b)]-'0'+rem;
if(x>=10) rem=(x-(x%10))/10;
else rem=0;
ans+=(x%10)+'0';
j--;
}
while(rem>=10)
{
ans+=(rem%10)+'0';
rem/=10;
}
if(rem>0) ans+=(rem+'0');
reverse(all(ans));
return ans;
}
main()
{
cin.tie(0) -> sync_with_stdio(0);
// string a, b;
// cin >> a >> b;
// cout << add(a, b) << endl;
// cout << (stol(add(a, b))==(stol(a)+stol(b)));
int n;
cin >> n;
string dp[n][n]={};
for(int i = 0;i < n;i++)
{
for(int j = 0;j < n;j++)
{
dp[i][j]='0';
}
}
dp[0][0]="1";
for(int i = 0;i < n;i++)
{
for(int j = 0;j < n;j++)
{
int x;
cin >> x;
if(i==n-1&&j==n-1) break;
// cout << i << " " << j << endl << flush;
if(i+x<n) dp[i+x][j]=add(dp[i+x][j], dp[i][j]);
if(j+x<n) dp[i][j+x]=add(dp[i][j+x], dp[i][j]);
}
}
// // cout << "here: " << endl << flush;
cout << dp[n-1][n-1];
// // cout << add("00001","12412");
}
컴파일 시 표준 에러 (stderr) 메시지
jump.cpp:47:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
47 | main()
| ^~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |