UVALive 6472 Powers of Pascal
标题手段:
他给了一个无限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的更多相关文章
- [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, ...
- [LeetCode] Pascal's Triangle 杨辉三角
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- 【leetcode】Pascal's Triangle II
题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...
- 【leetcode】Pascal's Triangle
题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...
- Pascal 语言中的关键字及保留字
absolute //指令(变量) abstract //指令(方法) and //运算符(布尔) array //类型 as //运算符(RTTI) asm //语句 assembler //向后兼 ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- LeetCode 118 Pascal's Triangle
Problem: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows ...
随机推荐
- Chrome 控制台不完全指南(转)
Chrome的开发者工具已经强大到没朋友的地步了,特别是其功能丰富界面友好的console,使用得当可以有如下功效: 更高「逼格」更快「开发调试」更强「进阶级的Frontender」 Bug无处遁形「 ...
- Chrome console(转)
阅读目录 写在前面 谷歌控制台Elements面板 查看元素上绑定的事情 样式操作 总况 console.log console.info console.error console.warn con ...
- 大约C++ const 全面总结
C++中的const关键字的使用方法很灵活,而使用const将大大改善程序的健壮性,本人依据各方面查到的资料进行总结例如以下,期望对朋友们有所帮助. Const 是C++中经常使用的类型修饰符,常类型 ...
- cocos2dx-2.x CCFileUtils文件管理分析(2)
于1于,我只是对整体结构进行了分析,然后,2于,我会在一些我们经常使用的分析功能. //获取给定文件名称的全路径 //以下这非常长一段凝视.通过举样例,像我们说明cocos2dx获取文件全路径的规则. ...
- Oracle 11g 的PL/SQL函数结果缓存
模拟Oracle性能诊断艺术做了两个试验样品.书上说的不承担RELIES_ON.果缓存的失效操作(result_cache RELIES_ON(test1,test2)).试验证明不正确,函数f1() ...
- Windows Server 2008 R2 SP1 下载地址
Windows Server 2008 R2 SP1 http://download.microsoft.com/download/0/A/F/0AFB5316-3062-494A-AB78-7FB0 ...
- Oracle listener lsnrctl
lsnrctl(Listener Control)是一家SQL*Net具,用于控制数据库listener,此工具提供了控制命令listener开端.停止,查看listener状态,更改listener ...
- x264 - open gop and closed gop
GOP - Group of picture(影像集团),它指的是两个I帧之间的距离. Reference(基准期). 它指的是两个P帧之间的距离. 简而言之, 跨参考gop的,变open gop: ...
- HDU 4896 Minimal Spanning Tree(矩阵高速功率)
意甲冠军: 给你一幅这样子生成的图,求最小生成树的边权和. 思路:对于i >= 6的点连回去的5条边,打表知907^53 mod 2333333 = 1,所以x的循环节长度为54,所以9个点为一 ...
- Cocos2d-x Auto-batching 浅浅的”深入分析”
Auto-batching是Cocos2d-x3.0新增的特性,目的是为了代替SpriteBatchNode,完毕渲染的批处理,提高绘制效率. 至于它有什么特点,能够看看官方文档,这里主要想探讨Aut ...