codeforces 514E Darth Vader and Tree (dp+快速幂)

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
      
      
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值