I. Improve SPAM
原创
©著作权归作者所有:来自51CTO博客作者wx63db9cf49ed95的原创作品,请联系作者获取转载授权,否则将追究法律责任
题意:
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;
}