HDU6129(杨辉三角和万恶的Lucas)
来源:互联网 发布:西瑞鞋子怎么样知乎 编辑:程序博客网 时间:2024/06/05 03:16
菜死了,比赛的时候T到哭
表格中
很简单就可以找出其中系数的规律,对于异或而言,异或相同的数偶数次相当于没有异或,那么我们只需要找出其中奇数就可以了.
注意了万恶的Lucas定理:
比赛的时候根本不知道,用Lucas求组合数,T到哭.
TLE code:
#include<cstdio>#include<algorithm>#include<cstring>#include<iostream>#include<string>//a&3==a%4using namespace std;#define ll long long#define mem(a) memset(a,0,sizeof(a))const double eps=1e-8;const int maxn=200010;//须填写const int inf=0x3f3f3f3f;const int p=1e9+7;int a[maxn+10];int b[maxn+10];long long Pow(long long a,long long b){ long long ans=1; while(b) { if(b&1) { b--; ans=(ans*a)%p; } b>>=1; a=(a*a)%p; } return ans;}long long C(long long n,long long m){ if(n<m) return 0; long long a=1,b=1; while(m) { a=(a*n)%p; b=(b*m)%p; m--; n--; } return (a*Pow(b,p-2))%p;}long long Lucas(long long n,long long m){ if(m==0) return 1; return Lucas(n/p,m/p)*C(n%p,m%p)%p;}bool C(int n,int b){ ll x=(ll)n; ll y=(ll)b; ll ans=Lucas(x,y); if(ans%2==1) return true; else return false;}int main(){ int kase; scanf("%d",&kase); while(kase--) { mem(a); mem(b); int n,m; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { scanf("%d",a+i); } for(int i=1;i<=n;i++) { for(int j=i;j>0;j--) { if(C(m-1+i-j,m-1)) { b[i]=b[i]^a[j]; } } } for(int i=1;i<n;i++) { printf("%d ",b[i]); } printf("%d\n",b[n]); } return 0;}
AC code:
#include<cstdio>#include<algorithm>#include<cstring>#include<iostream>#include<string>//a&3==a%4using namespace std;#define ll long long#define mem(a) memset(a,0,sizeof(a))const double eps=1e-8;const int maxn=200010;//须填写const int inf=0x3f3f3f3f;const int mod=1e9+7;int a[maxn];int b[maxn];int main(){ int kase; scanf("%d",&kase); while(kase--) { mem(a); mem(b); int n,m; scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { scanf("%d",a+i); } for(int i=1;i<=n;i++) { int x=i+m-2; int y=i-1; if((x&y)==y)//y的1位置是x的子集则(x&y)==y { for(int j=i;j<=n;j++) b[j]^=a[j-i+1]; } } for(int i=1;i<n;i++) { printf("%d ",b[i]); } printf("%d\n",b[n]); } return 0;}
阅读全文
0 0
- HDU6129(杨辉三角和万恶的Lucas)
- hdu6129-( Lucas定理)
- hdu5698瞬间移动+杨辉三角+LUCAS
- HDU 5794(杨辉三角+Lucas)
- HDU6129 Just do it(前缀异或+杨辉三角)
- hdu6129 Just do it 2017多校第七场1010 杨辉三角+规律
- HDU 4349 组合数的奇数个数-杨辉三角&Lucas定理
- 组合数取模(杨辉三角+Lucas定理+模合数)
- hdu6129
- hdu6129
- HDU 6129 Just do it【杨辉三角+思维+Lucas定理】
- HDU 6129 Just do it(杨辉三角+lucas \ 记忆化dp)
- java的杨辉三角和菱形
- 最标准的杨辉三角和一般的杨辉三角
- 汉诺塔和杨辉三角
- 【HDU3944 】DP?【LUCAS定理+阶乘预处理】 【杨辉三角中的点(第n行m列),问你从(0,0)点走到该点经过的点最少的权值和(只能向下走或斜着走)。同时对素数p取余】
- 队列的简单应用-杨辉三角和约瑟夫环
- 杨辉三角的递归和非递归实现
- 小程序tabBar的一些用法
- JAVA SE --接口
- 笔试题:利用素数定理计算100以内素数的个数
- BZOJ1798 AHOI2009 维护数列
- DELETE_FAILED_INTERNAL_ERROR 小米之殇
- HDU6129(杨辉三角和万恶的Lucas)
- 如果有只时光鸡 - 语义化的感悟
- IOS 将文字写绘制成图片并转换为像素数据
- MongoDB windows基础配置及集群搭建
- 贝叶斯算法
- 纪念品分组
- Python操作MySQL
- Android单元测试-对View的测试
- Java8系列之重新认识HashMap