标题手段:

他给了一个无限Pascal阵,定义了powers,然后询问power为P的pascal矩阵里面的第R行C列的元素是多少。

最開始读错题意了...然后 就成了一个神得不得了的题了。后来请教的别人。

感觉能够用矩阵高速幂做。

然后,不用高速幂的话,你会惊奇的发现,变成了找规律的题了...

答案成了 comb(i,j) * P^(i-j)

对于comb(i,j),利用组合数性质,能够得到,当j>i-j 的时候 j=i-j;

由于题目说答案不会爆long long  所以能够预处理,大概56左右,后发现50也行

组合数公式 Comb(i,j)=Comb(i-1,j)+Comb(i-1,j-1);

Ps:写这个是为了提醒自己....有时候打表找规律也是一种做一些数学有关的题的手段,当时实在不知道怎么做了时。

代码例如以下。再次感谢xxx

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std; const int maxn=100000;
typedef long long LL;
LL C[maxn+2][52];
LL kk,k,p,r,c; void init()
{ for(int i=0;i<=maxn;i++) C[i][0]=1;
for(int i=1;i<=maxn;i++)
for(int j=1;j<=min(i,50);j++)
C[i][j]=C[i-1][j]+C[i-1][j-1];
}
int main()
{
init();
//cout<<C[3][1]<<endl;
scanf("%lld",&k);
while(k--)
{
scanf("%lld%lld%lld%lld",&kk,&p,&r,&c);
LL ans=1;
for(int i=1;i<=(r-c);i++)
ans*=p;
if(c>r/2) c=r-c;
ans*=C[r][c];
printf("%lld %lld\n",kk,ans);
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

UVALive 6472 Powers of Pascal的更多相关文章

  1. [LeetCode] Pascal's Triangle II 杨辉三角之二

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

  2. [LeetCode] Pascal's Triangle 杨辉三角

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...

  3. 【leetcode】Pascal's Triangle II

    题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...

  4. 【leetcode】Pascal's Triangle

    题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...

  5. Pascal 语言中的关键字及保留字

    absolute //指令(变量) abstract //指令(方法) and //运算符(布尔) array //类型 as //运算符(RTTI) asm //语句 assembler //向后兼 ...

  6. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  7. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  8. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  9. LeetCode 118 Pascal's Triangle

    Problem: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows  ...

随机推荐

  1. 搭建SSH

    搭建SSH详细步骤及相关说明   因为手里已有相关jar,为方便我搭建的是:Struts2.0+Hibernate3.3+Spring3.0,数据库:MySQL 如果想搭建最新的,在官网上下载最新ja ...

  2. DataGridView显示数据的两种方法

    1.简介 DataGridView空间是我们经常使用的显示数据的控件,它有极高的可配置性和可扩展性. 2.显示数据 DataGridView显示数据一般我们经常使用的有两种方法,一种是直接设置Data ...

  3. Spark 1.0.0版本发布

    前言 如今Spark终于迈出了里程碑一步,1.0.0标记的版本号出版物Spark1.0时代.1.0.0版本号不仅增加了非常多新特性.而且提供了更好的API支持.Spark SQL作为一个新的组件增加. ...

  4. Android - 分享内容 - 接收其他APP的内容

    就象程序可以发送数据给其他程序,所以也可以接收其他程序的数据.想一下用户如何和程序交互,以及想从其他程序接收什么样类型的数据.例如,一个社交程序可能对接收其他程序的文字(比如有趣的网址)感兴趣.Goo ...

  5. Zen Coding in Visual Studio 2012

    http://www.johnpapa.net/zen-coding-in-visual-studio-2012 Zen Coding is a faster way to write HTML us ...

  6. 【Android进阶】Android程序与JavaScript之间的简单调用

    本篇将讲解一个简单的Android与JavaScript之间的简单调用的小程序 效果图 工程结构 HTMLActivity.java代码 package com.example.javatojs; i ...

  7. 第22题 Rotate List

    Given a list, rotate the list to the right by k places, where k is non-negative. For example: Given  ...

  8. 4.4、Libgdx用法查询执行环境相关性

    (原版的:http://www.libgdx.cn/topic/46/4-4-libgdx%E4%BD%BF%E7%94%A8%E6%96%B9%E6%B3%95%E6%9F%A5%E8%AF%A2% ...

  9. extjs_09_定义自己的页面组件

    1.项目截图 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYWRhbV93enM=/font/5a6L5L2T/fontsize/400/fill/I0J ...

  10. CSDN markdown 编辑 第五章 UML

    这里大概只能产生两种类型的图: 序列图 框图 序列图 ```sequence A->B: 一句话证明你非常寂寞. Note right of B: thinking B->B: count ...