Submission #37148
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include<bits/stdc++.h> using namespace std; int h,w; int mp[1001][1001]; int memo[1001][1001]; int dp( int i, int j){ int ret=0; if (memo[i][j]!=-1) return memo[i][j]; if (i==h&&j==w) return 0; else if (i<h&&j==w){ ret+=dp(i+1,j)+mp[i+1][j]; } else if (j<w&&i==h){ ret+=dp(i,j+1)+mp[i][j+1]; } else { ret+=max(dp(i,j+1)+mp[i][j+1],dp(i+1,j)+mp[i+1][j]); } return memo[i][j]=ret; } int main(){ memset (memo,-1, sizeof (memo)); cin>>h>>w; for ( int i=1;i<=h;i++){ for ( int j=1;j<=w;j++){ cin>>mp[i][j]; } } cout<<dp(1,1)+mp[1][1]<<endl; return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0910 - 百円以下の拾得物 |
ユーザー名 | ei1725 |
投稿日時 | 2018-06-12 17:55:13 |
言語 | C++11 |
状態 | Accepted |
得点 | 3 |
ソースコード長 | 660 Byte |
最大実行時間 | 184 ms |
最大メモリ使用量 | 8440 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 3 / 3 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in01.txt | AC | 27 ms | 4576 KB |
1
|
in02.txt | AC | 29 ms | 4552 KB |
1
|
in03.txt | AC | 28 ms | 4536 KB |
1
|
in04.txt | AC | 22 ms | 4512 KB |
1
|
in05.txt | AC | 21 ms | 4616 KB |
1
|
in06.txt | AC | 167 ms | 8436 KB |
1
|
in07.txt | AC | 170 ms | 8440 KB |
1
|
in08.txt | AC | 180 ms | 8436 KB |
1
|
in09.txt | AC | 184 ms | 8436 KB |
1
|
in10.txt | AC | 27 ms | 6644 KB |
1
|
in11.txt | AC | 126 ms | 7388 KB |
1
|
sample_in_1.txt | AC | 23 ms | 4740 KB |
1
|
sample_in_2.txt | AC | 26 ms | 4716 KB |
1
|