이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define A first
#define B second
#define MP make_pair
#define ms(a, x) memset(a, x, sizeof(a))
#define boost() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pld;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const int mxN=1e4+5;
ll n, m, h, dp[mxN][405];
vector <vector<pii>> adj(mxN);
ll solve(int node, int date){
if(date < 0)
return 0;
if(node == 0 && date == 0)
return 1;
if(dp[node][date] != -1)
return dp[node][date];
ll sum=0;
bool over=false;
for(auto [x, y]:adj[node]){
if(x < node){
for(int i=0; i<m; i++){
sum += solve(x, date-y-i);
if(sum >= 5e8+1){
sum = 5e8+1;
over=true;
break;
}
}
if(over)
break;
}
}
return dp[node][date]=sum;
}
int main(){
boost();
ms(dp, -1);
cin >> n >> m >> h;
for(int i=0; i<n-1; i++){
for(int j=0; j<h; j++){
int x, y;
cin >> x >> y;
adj[x].push_back({i, y});
}
}
for(int i=0; i<=m-1; i++)
cout << solve(n-1, i) << " ";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |