codeforces 514E Darth Vader and Tree (dp+快速幂)
题意:
有一棵树,每个节点有n个儿子,给出父亲到每个儿子的距离di,问离祖先距离不超过x的子孙有多少个(子孙包括祖先)对1e9+7取模。
限制:
1 <= n <= 1e5; 0 <= x <= 1e9; 1 <= di <= 100
思路:
因为di <= 100,所以可以用快速幂来处理这道题,
大概过程为:先用dp算出前100的答案,剩下的用快速幂来处理。
/*codeforces 514E Darth Vader and Tree
题意:
有一棵树,每个节点有n个儿子,给出父亲到每个儿子的距离di,问离祖先距离不超过x的子孙有多少个(子孙包括祖先)对1e9+7取模。
限制:
1 <= n <= 1e5; 0 <= x <= 1e9; 1 <= di <= 100
思路:
因为di <= 100,所以可以用快速幂来处理这道题,
大概过程为:先用dp算出前100的答案,剩下的用快速幂来处理。
*/
#include
#include
using namespace std;
const int MOD=1e9+7;
#define LL __int64
struct Matrix
{
int a[105][105]; //
int n,m;
Matrix(int _n=0,int _m=0,LL val=0)
{
n=_n; m=_m;
for(int i=0;i
/*codeforces 514E Darth Vader and Tree
题意:
有一棵树,每个节点有n个儿子,给出父亲到每个儿子的距离di,问离祖先距离不超过x的子孙有多少个(子孙包括祖先)对1e9+7取模。
限制:
1 <= n <= 1e5; 0 <= x <= 1e9; 1 <= di <= 100
思路:
因为di <= 100,所以可以用快速幂来处理这道题,
大概过程为:先用dp算出前100的答案,剩下的用快速幂来处理。
*/
#include
#include
using namespace std;
const int MOD=1e9+7;
#define LL __int64
struct Matrix
{
int a[105][105]; //
int n,m;
Matrix(int _n=0,int _m=0,LL val=0)
{
n=_n; m=_m;
for(int i=0;i