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

#include <algorithm> // require sort next_permutation count __gcd reverse etc.
#include <cctype>    // require tolower, toupper
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>  // require scanf printf
#include <cstdlib> // require abs exit
#include <cstring> // require memset
#include <ctime>
#include <deque>
#include <fstream> // require freopen
#include <functional>
#include <iomanip> // require setw
#include <iostream>
#include <limits>
#include <map>
#include <numeric> // require accumulate
#include <queue>
#include <set>
#include <sstream> // require stringstream
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(A) A.begin(), A.end()
#define DEBUG 0

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
string FILE_NAME = "testcase.0097";
string NAME;
string itos(int n) {
  stringstream ss;
  ss << n;

  return ss.str();
}

ll dp[101][1001];

int main() {
//	cut here before submit
#if DEBUG
  NAME = FILE_NAME;
  int CNT = 1;
  NAME += itos(CNT);
  while (freopen(NAME.c_str(), "r", stdin) != NULL) {
#endif
    ios_base::sync_with_stdio(0);
    int n, s;
    while (cin >> n >> s, n) {
      memset(dp, 0LL, sizeof(dp));
      dp[0][0] = 1LL;
      for (int i = 0; i <= 100; i++) {
        for (int j = 9; j >= 0; j--) {
          for (int k = 0; i + k <= 1000; k++) {
            dp[j + 1][i + k] += dp[j][k];
          } // end for
        }   // end for
      }     // end for
      cout << dp[n][s] << endl;
    } // end rep
#if DEBUG
    CNT++; // cut here before submit
    NAME = FILE_NAME;
    NAME += itos(CNT);
  } // end loop; cut here before submit
#endif
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm> // require sort next_permutation count __gcd reverse etc.
#include <cctype>    // require tolower, toupper
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>  // require scanf printf
#include <cstdlib> // require abs exit
#include <cstring> // require memset
#include <ctime>
#include <deque>
#include <fstream> // require freopen
#include <functional>
#include <iomanip> // require setw
#include <iostream>
#include <limits>
#include <map>
#include <numeric> // require accumulate
#include <queue>
#include <set>
#include <sstream> // require stringstream
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(A) A.begin(), A.end()
#define DEBUG 0

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
string FILE_NAME = "testcase.0097";
string NAME;
string itos(int n) {
  stringstream ss;
  ss << n;

  return ss.str();
}
int n, s;
bool used[101];
int dp[10][1001];

void dfs(int depth, int curr) {
  if (depth > n || curr > s)
    return;
  dp[depth][curr]++;
  rep(i, 100) {
    if (!used[i]) {
      used[i] = true;
      dfs(depth + 1, curr + i);
      used[i] = false;
    } // end if
  }   // end rep
}

int main() {
//	cut here before submit
#if DEBUG
  NAME = FILE_NAME;
  int CNT = 1;
  NAME += itos(CNT);
  while (freopen(NAME.c_str(), "r", stdin) != NULL) {
#endif
    ios_base::sync_with_stdio(0);
    while (cin >> n >> s, n) {
      memset(used, false, sizeof(used));
      memset(dp, 0, sizeof(dp));
      dfs(0, 0);
      cout << dp[n][s] / 6 << endl;
    } // end rep

#if DEBUG
    CNT++; // cut here before submit
    NAME = FILE_NAME;
    NAME += itos(CNT);
  } // end loop; cut here before submit
#endif
  return 0;
}