Problem p00097 (C++) — buggy submission, verdict: Time Limit Exceeded

#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

int dp[10][865][102] = {};

long long int saiki(int n, int s, int x) {
  if (n == 1) {
    if (s <= x && s >= 0)
      return 1;
    else
      return 0;
  }
  long long int ans = 0;
  for (int i = min(x, s); i >= 0; i--) {
    if (dp[n - 1][s - i][i - 1] == -1) {
      dp[n - 1][s - i][i - 1] = saiki(n - 1, s - i, i - 1);
    }
    ans += dp[n - 1][s - i][i - 1];
  }
  return ans;
}

int main() {
  int n, s;
  for (size_t i = 0; i < 10; i++) {
    for (size_t j = 0; j < 865; j++) {
      for (size_t k = 0; k < 102; k++) {
        dp[i][j][k] = -1;
      }
    }
  }
  while (cin >> n >> s, n || s) {
    if (s > 864)
      cout << 0 << endl;
    else
      cout << saiki(n, s, min(100, s)) << endl;
  }
}

Error: TLE

Fixed submission:

#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

int dp[10][1001][102] = {};

long long int saiki(int n, int s, int x) {
  if (n == 1) {
    if (s <= x && s >= 0)
      return 1;
    else
      return 0;
  }
  long long int ans = 0;
  for (int i = min(x, s); i >= 0; i--) {
    if (dp[n - 1][s - i][i - 1] == 0) {
      dp[n - 1][s - i][i - 1] = saiki(n - 1, s - i, i - 1);
    }
    ans += dp[n - 1][s - i][i - 1];
  }
  return ans;
}

int main() {
  int n, s;
  while (cin >> n >> s, n || s) {
    if (s > 864)
      cout << 0 << endl;
    else
      cout << saiki(n, s, min(100, s)) << endl;
  }
}