比赛 |
NOIP模拟赛by mzx Day2 |
评测结果 |
AAAAAAAAAA |
题目名称 |
森林大礼包 |
最终得分 |
100 |
用户昵称 |
Phosphorus15 |
运行时间 |
1.052 s |
代码语言 |
C++ |
内存使用 |
0.28 MiB |
提交时间 |
2016-10-20 18:53:02 |
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <vector>
#define MOD (1000000007)
//#define DEBUG_MODE
#ifdef DEBUG_MODE
using std::cin;
using std::cout;
#else
using std::ifstream;
using std::ofstream;
ifstream cin("three_squirrels.in");
ofstream cout("three_squirrels.out");
#endif
using std::endl;
using std::vector;
struct Package{
int n;
int pre;
vector<int> ic;
Package():n(0),pre(-1){
}
};
Package * packs;
int n,m;
int calc(int pkg){
if(packs[pkg].pre!=-1)
return packs[pkg].pre;
int r = 0;
for(vector<int>::iterator it = packs[pkg].ic.begin();it!=packs[pkg].ic.end();it++){
r += calc(*it);
r %= MOD;
}
packs[pkg].pre = r;
return r;
}
int main(int argc,char ** argv){
int k,t;
cin>>n;
packs = new Package[n+1];
for(int x=1;x<=n;x++){
packs[x] = Package();
packs[x].n = x;
cin>>k;
for(int y=0;y!=k;y++){
cin>>t;
packs[x].ic.push_back(t);
}
}
packs[0].pre = 1;
packs[0].n = 0;
cout<<calc(n)<<endl;
return 0;
}