Skip to content

Instantly share code, notes, and snippets.

@Tdrj2716
Created March 26, 2018 13:36
Show Gist options
  • Save Tdrj2716/ffbf209a4e8c153873ea2b7e06322567 to your computer and use it in GitHub Desktop.
Save Tdrj2716/ffbf209a4e8c153873ea2b7e06322567 to your computer and use it in GitHub Desktop.
動的計画法の練習(Combination)
#include <stdio.h>
#include <algorithm>
using namespace std;
int memo[30][30];
int dp(int i, int j)
{
if(memo[i][j] != -1)
return memo[i][j];
else if(i == 0 || j == 0)
return memo[i][j] = 1;
else
return memo[i][j] = dp(i-1, j) + dp(i, j-1);
}
int main()
{
int h, w;
scanf("%d %d", &h, &w);
fill(memo[0], memo[h], -1);
printf("%d", dp(h-1, w-1));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment