I. Improve SPAM_比赛


I. Improve SPAM_比赛_02


I. Improve SPAM_比赛_03

题意:

DAG上从1号点到其他终止点的路径方案数

AC代码:

const int N = 2020;
const ll mod = 1e9 + 7;
vector<ll> edge[N];
ll n, m, dp[N], cnt = 0, ans = 0;

ll dfs(ll cur)
{
if (dp[cur] != -1)
return dp[cur];
if (cur > m)
{
cnt++;
dp[cur] = 1;
return dp[cur];
}
ll sum = 0;
for (auto x : edge[cur])
sum = ((dfs(x) % mod) + sum) % mod;
dp[cur] = sum;
return sum;
}

int main()
{
rep(i, 0, N - 1)
dp[i] = -1;
sldd(n, m);
rep(i, 1, m)
{
ll x;
sld(x);
while (x--)
{
ll y;
sld(y);
edge[i].pb(y);
}
sort(edge[i].begin(), edge[i].end());
}
ll ans = dfs(1);
pldd(ans, cnt);
return 0;
}