HDU 5656 CA Loves GCD dp,常数优化
来源:互联网 发布:java date类 编辑:程序博客网 时间:2024/05/19 00:35
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5656
题意:
解法:
//HDU 5656#include <bits/stdc++.h>using namespace std;const int maxn = 1050;const int mod = 100000007;int dp[maxn][maxn], a[maxn], n;///dp[i][j]表示在前i个数中,选出若干个数使得它们的gcd为j的方案数,///于是只需要枚举第i+1个数是否被选中来转移就可以了long long ans;int gcd(int a, int b){ return b==0?a:gcd(b, a%b);}void update(int &x, long long y){ x += y; if(x>=mod) x-=mod;}int main(){ int t; scanf("%d", &t); while(t--) { memset(dp, 0, sizeof(dp)); dp[0][0] = 1; ans = 0; scanf("%d", &n); for(int i = 1; i <= n; i++) scanf("%d", &a[i]); for(int i = 0; i < n; i++){ for(int j = 0; j < maxn; j++){ if(dp[i][j]){//不加限制会T (dp[i+1][j] += dp[i][j])%=mod; (dp[i+1][gcd(j, a[i+1])] += dp[i][j])%=mod; } } } for(int i = 1; i < maxn; i++){ (ans += 1LL*i*dp[n][i]%mod)%=mod; } printf("%d\n", ans); } return 0;}
0 0
- HDU 5656 CA Loves GCD dp,常数优化
- HDU 5656 CA Loves GCD (dp)
- hdu CA Loves GCD dp
- HDU 5656:CA Loves GCD
- HDU 5656 CA Loves GCD
- HDU 5656 CA Loves GCD
- hdu 5656 CA Loves GCD
- HDU 5656 CA Loves GCD
- HDU 5656 CA Loves GCD
- HDU 5656 CA Loves GCD
- HDU 5656 CA Loves GCD (BestCoder Round #78) DP
- hdu 5656 CA Loves GCD(穷举子集类dp)
- HDU - CA Loves GCD
- hdoj 5656 CA Loves GCD 【dp】
- hdu 5656 CA Loves GCD(dp+gcd)(Bestcoder #78 1002)
- HDU 5656 CA Loves GCD 枚举GCD+容斥
- HDU 5656 CA Loves GCD 01背包+gcd
- bc 4.2 1002 CA Loves GCD dp
- MongoDB基本用法(增删改高级查询)
- 指针与内存
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'studentContr
- andorid 短信通知广播接收。
- python封装安卓查找元素方法V1.0
- HDU 5656 CA Loves GCD dp,常数优化
- oracle中如何将日期转成时间戳
- jQuery_如何用js或jQuery实现input失焦后,为空则为红色边框,不为空则为绿色边框?
- 原型设计模式
- 如何上传本地代码到git/coding
- MyEclipse配置输出控制台信息至文本文件中
- c# 委托与事件 学习笔记
- dos命令映射文件夹为虚拟磁盘分区
- cin.()和cin.getline()