标题手段:

他给了一个无限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. [LeetCode217]Contains Duplicate

    题目:Given an array of integers, find if the array contains any duplicates. Your function should retur ...

  2. JDBC连接数据库 prepareStatement

    import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import ...

  3. IT忍者神龟之使用 PowerDesigner

    1. 启动 PowerDesigner 新建物理数据模型 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdmlweWhk/font/5a6L5L2T/fon ...

  4. ASP.NET自定义控件组件开发 第四章 组合控件开发CompositeControl

    原文:ASP.NET自定义控件组件开发 第四章 组合控件开发CompositeControl 第四章 组合控件开发CompositeControl 大家好,今天我们来实现一个自定义的控件,之前我们已经 ...

  5. JSON 数据使用

    当用不同的数据的模板需要更换时.假设数据点的量.使用json非常方便. json物: var JSONObject= { "name":"Bill Gates" ...

  6. Mac OS X 在捕捉AppLAN通信包

    Mac OS X 在捕捉AppLAN通信包 一.拍摄模式 由于工作关系.经常要分析App wifi通讯协议.我的开发电脑是Mac Book. 大体有例如以下几种模式: + App与server进行ht ...

  7. 3D数学--学习笔记(五岁以下儿童):总结一些概念(避免遗忘!)

    下面是一些概念只是一个简单的解释,这里是它的一个简单的了解! 当人们谈论,我能理解有关. 1.正交投影: 投影.这意味着降维操作. 全部的点都被拉平至垂直的轴(2D)或平面(3D)上.这样的类型的投影 ...

  8. SQL Server中的TempDB管理——TempDB基本知识(为什么需要版本存储区)

    原文:SQL Server中的TempDB管理--TempDB基本知识(为什么需要版本存储区) 参考资料来自: http://blogs.msdn.com/b/sqlserverstorageengi ...

  9. HDU 2203 亲串(kmp)

    Problem Description 随着人们年龄的增长更大,更聪明还是越大越愚蠢,这是一个值,相同的问题Eddy也一直在思考,由于他在非常小的时候就知道亲和串怎样推断了,可是发现,如今长大了却不知 ...

  10. java并行体系结构

    并行编程 线程通信 共享内存和消息传递 线程同步 控制不同线程的运行顺序 java并发 基于共享内存模型 指令重排序 编译器重排序 处理器重排序 cpu重排序 写缓存区(cache.寄存器) 内存屏障 ...