标题手段:

他给了一个无限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. Heritage from father

    Problem Description Famous Harry Potter,who seemd to be a normal and poor boy,is actually a wizard.E ...

  2. 【转】java JTable排序和过滤

    JTable排序 在Java SE 6中除了java.awt被更新外,javax.swing同时也有了很大的改进.在C/S程序中我们会经常使 用到"表".如我们可以在查询数据库后将 ...

  3. Akka.NET是Java/Scala 流行框架Akka的一个 .NET 开源移植

    Akka.NET v1.0 已发布,支持Mono Akka.NET 是Java/Scala 流行框架Akka的一个 .NET 开源移植.可用于构建高并发,分布式和容错事件驱动的应用在 .NET 和 M ...

  4. SpringMVC源码解析- HandlerAdapter - ModelFactory(转)

    ModelFactory主要是两个职责: 1. 初始化model 2. 处理器执行后将modle中相应参数设置到SessionAttributes中 我们来看看具体的处理逻辑(直接充当分析目录): 1 ...

  5. C# - is

     Checks if an object is compatible with a given type. An is expression evaluates to true if the pr ...

  6. Oracle 如何提交手册Cluster Table事务

    环境遇到ora-00600 4000错误,该目的是参与cluster table,什么我这里有以下简单的模拟.以供参考! ++++创建一个测试表 ? 1 2 3 4 5 6 7 8 9 10 11 1 ...

  7. Mysql 演示示例存储过程

    DELIMITER $ CREATE PROCEDURE generate_Equipment(district INT,warehouseNO VARCHAR(10) ) BEGIN  DECLAR ...

  8. 兼容的网页宽度margin padding

    hack兼容: -moz-  /* Firefox 4 */ -webkit- /* Safari 和 Chrome */ -o-  /* Opera */ IE6承认*和_和+,不承认!import ...

  9. cocos2d-x3.0 lua学习(一个)

    最近开始学习Lua这里记录下一个写简单Lua代码,但我在写Lua代码.自己主动的代码提示的一些问题,谁希望提供下很好的解决方案,编辑我用SubLime Text2 test.lua.这里创建一个场景, ...

  10. Kafka (一)

    使用Kafka最新版本0.9 Kafka 配置 1. 安装 首先需要安装Java,推荐安装Java8,不然会出现一些莫名其妙的错误 kafka_2.11-0.9.0.0.tgz tar -xzf ka ...