比赛 NOIP模拟赛by mzx Day2 评测结果 AAAAAAAAAA
题目名称 森林大礼包 最终得分 100
用户昵称 可以的. 运行时间 0.510 s
代码语言 C++ 内存使用 7.84 MiB
提交时间 2016-10-20 21:46:27
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <deque>
#define Mem(a,v) memset(a,v,sizeof(a))
using namespace std;
/*
freopen(".in","r",stdin);
	freopen(".out","w",stdout);
getchar(); getchar();
	return 0;
*/
const int inf = 1000000007; 
#define maxn 100010
int N,f[maxn],len,head[maxn];
struct Edge
{
	int to,next;	
}e[maxn*10];
void insert(int x,int y){
	e[++len].to = y; 
	e[len].next = head[x]; head[x] = len;	
}
void read(int &res){
	int x,f=1; char ch;
	while(ch=getchar(),ch<'0'||ch>'9')if(ch=='-')f=-1;
	x=ch-48;
	while(ch=getchar(),ch>='0'&&ch<='9')x=x*10+ch-48;
	res = x * f;	
}
void Read(){
	read(N); 
	for(int i = 1; i <= N ;i ++ ){
		int num; read(num);
		for(int j = 1 ;j <= num ;j ++){
			int x; read(x); insert(i,x);
		}
	}	
}		
int Dp(int x){
	if(x == 0) return f[x] = 1;
	if(f[x]) return f[x];
	for(int i = head[x]; i ;i = e[i].next){
		f[x] += Dp(e[i].to)%inf;
		f[x] %= inf;	
	}	
	return f[x]%inf;
}
void Answer(){
	printf("%d\n",Dp(N)%inf);	
}
int main(){
	freopen("three_squirrels.in","r",stdin);
	freopen("three_squirrels.out","w",stdout);
	
	Read();
	Answer();
	
//	getchar(); getchar();
	return 0;
}
/*

*/