POJ 1664 放苹果
递推,放苹果
1 #include <algorithm> 2 #include <iostream> 3 #include <cstring> 4 #include <cstdio> 5 #include <cctype> 6 7 using namespace std; 8 9 inline void read(long long &x) 10 { 11 int k = 1; x = 0; 12 char c = getchar(); 13 while (!isdigit(c)) 14 if (c == '-') k = - 1, c = getchar(); 15 else c = getchar(); 16 while (isdigit(c)) 17 x = (x << 1) + (x << 3) + (c ^ 48), 18 c = getchar(); 19 x *= k; 20 } 21 22 long long T, n, m, dp[55][55]; 23 24 int main() 25 { 26 read(T); 27 for (int i = 1; i <= 50; ++i) 28 for (int j = 0; j <= 50; ++j) 29 if (i == 1 || j == 0) dp[i][j] = 1; 30 else if (i > j) dp[i][j] = dp[j][j]; 31 else if (i <= j) dp[i][j] = dp[i][j - i] + dp[i - 1][j]; 32 for (int plk = 1; plk <= T; ++plk) 33 read(n), read(m), printf("%d\n", dp[m][n]); 34 return 0; 35 }