51nod oj 1256 1119 1013 1083 1014 1081<组合数+逆元+快速幂,DP,枚举,树状数组>
来源:互联网 发布:js获取url网页内容 编辑:程序博客网 时间:2024/06/14 03:33
题目链接:1256
求逆元用拓展欧几里德--详情请看 点击打开链接
代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define LL long long LL extend_gcd(LL a,LL b,LL &x,LL &y){if (b==0){x=1;y=0;return a;}else{LL t=extend_gcd(b,a%b,y,x);y-=x*(a/b);return t;}}int main(){LL n,m,x,y;scanf("%lld%lld",&m,&n);extend_gcd(m,n,x,y);x=(x%n+n)%n;printf("%lld\n",x);}
题目链接:1119
题解与 LightOJ - 1067 数论<100000左右的组合数取模求法《逆元》> 一样
代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define LL long longLL dis[2000100],ni[2000100];LL mod=1000000007;LL po(LL xx,LL k){ LL lp=1,hu=xx; while (k) { if (k%2==1) lp=(lp*hu)%mod; hu=(hu*hu)%mod; k/=2; } return lp;}int main(){ int n,m; scanf("%d%d",&n,&m); int da=n+m-2; int xi=n-1; dis[0]=ni[0]=1; for (int i=1;i<=da;i++) { dis[i]=dis[i-1]*i%mod; } ni[xi]=po(dis[xi],mod-2); ni[da-xi]=po(dis[da-xi],mod-2); LL ans=dis[da]*ni[xi]%mod*ni[da-xi]%mod; printf("%lld\n",ans); return 0;}
题目链接:1013
快速幂+逆元
代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define LL long longLL mod=1000000007;LL extend(LL a,LL b,LL &x,LL &y){ if (b==0) { x=1;y=0; return a; } else { LL t=extend(b,a%b,y,x); y-=x*(a/b); return t; }}LL pp(LL x,LL k){ LL lp=1,hu=x; while (k) { if (k%2) { lp=lp*hu%mod; } hu=(hu*hu)%mod; k/=2; } return lp;}int main(){ int n;scanf("%d",&n); LL p=pp(3,n+1); p-=1; LL x,y,a=2; extend(a,mod,x,y); x=(x%mod+mod)%mod; LL ans=p*x%mod; printf("%lld\n",ans); return 0;}
题目链接:1083
简单dp
代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define LL long longLL map[600][600],dp[600][600];int main(){ int n;scanf("%d",&n); memset(map,0,sizeof(map)); memset(dp,0,sizeof(dp)); for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) scanf("%lld",&map[i][j]); for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) dp[i][j]=max(dp[i-1][j],dp[i][j-1])+map[i][j]; printf("%lld\n",dp[n][n]); return 0;}
题目链接:1014
枚举----无语--
代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;long long i,a,p;int main(){ scanf("%lld%lld",&p,&a); bool fafe=true; for (i=1;i<=p;i++) { if (i*i%p==a) { if (fafe) { printf("%lld",i); fafe=false; } else printf(" %lld",i); } } if (fafe) printf("No Solution\n"); else printf("\n"); return 0;}
题解:树状数组求和
代码:
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;#define low(x) x&-x#define LL long longint n;LL shu[50050];void ADD(int ii,LL xx){for (ii;ii<=n;ii+=low(ii))shu[ii]+=xx;}LL QUERY(int ii){LL lp=0;for (ii;ii>0;ii-=low(ii))lp+=shu[ii];return lp;}int main(){scanf("%d",&n);LL a;memset(shu,0,sizeof(shu));for (int i=1;i<=n;i++){scanf("%lld",&a);ADD(i,a);}int m;scanf("%d",&m);int b,c;while (m--){scanf("%d%d",&b,&c);printf("%lld\n",QUERY(b+c-1)-QUERY(b-1));}return 0;}
0 0
- 51nod oj 1256 1119 1013 1083 1014 1081<组合数+逆元+快速幂,DP,枚举,树状数组>
- 51nod 1119 机器人走方格V2(求组合数,费马小定理+快速幂/逆元+gcd)
- 51nod 1118 机器人走方格(组合数【逆元】,dp)
- 51nod 1013【快速幂+逆元】
- 51 nod 加号分配 组合数学(逆元,快速幂)
- 2017-07-25 51nod 1119 组合数取模 某数关于质数的逆元
- zoj3903-数学公式(快速幂除法逆元组合数模板)
- 【板子】gcd、exgcd、乘法逆元、快速幂、快速乘、筛素数、快速求逆元、组合数
- 【板子】gcd、exgcd、乘法逆元、快速幂、快速乘、筛素数、快速求逆元、组合数
- light oj 1102 Problem Makes Problem [组合数+逆元]
- 51nod 1019 逆序数 (归并|树状数组)
- 51nod 1019 逆序数(树状数组)
- 51 nod 1019 逆序数【归并排序||树状数组】
- 51Nod 1019 逆序数(树状数组/归并)
- #95 qsc oj 喵哈哈村的秘境探险(四)(数位dp, 组合数,快速幂)
- 【51Nod】1119 - 机器人走方格V2(逆元 & 费马小定理 & 快速幂)
- 51nod 1013 3的幂的和(等比数列求和_快速幂+逆元)
- 51Nod 1013 3的幂的和(快速幂+逆元)
- DNS域名解析
- 2016年8月7日,22岁生日
- 常量和变量
- linux 路由表设置 之 route 指令详解
- jboss: option requires an argument --c jboss启动报错
- 51nod oj 1256 1119 1013 1083 1014 1081<组合数+逆元+快速幂,DP,枚举,树状数组>
- Java控_01原创工具类(001)_深度的对象非null转换工具V1.0
- Python 文件处理
- 最快最简单的排序——桶排序
- Spark Streaming + Kafka Manager + (Kafka-spark-consumer) 组合
- 继承关系下new子类对象,会发生什么?
- Python调用Matplotlib绘制分布点并且添加标签
- 计算机概论
- 索引