HDU 6030 Happy Necklace】的更多相关文章

Problem Description Little Q wants to buy a necklace for his girlfriend. Necklaces are single strings composed of multiple red and blue beads. Little Q desperately wants to impress his girlfriend, he knows that she will like the necklace only if for…
矩阵快速幂. 因为任意素数长度都要满足,所以$3$必须满足,$3$一旦满足,其余的肯定满足,也就是说只要考虑字符串末尾两位即可,$dp$一下就可以算方案数了.$n$较大,可以矩阵加速. #include <bits/stdc++.h> using namespace std; ; const long long inf=1e18; int T; long long n; struct Matrix { ][]; int R, C; Matrix operator*(Matrix b); };…
hdu 5730 Shell Necklace 题意:求递推式\(f_n = \sum_{i=1}^n a_i f_{n-i}\),模313 多么优秀的模板题 可以用分治fft,也可以多项式求逆 分治fft 注意过程中把r-l+1当做次数界就可以了,因为其中一个向量是[l,mid],我们只需要[mid+1,r]的结果. 多项式求逆 变成了 \[ A(x) = \frac{f_0}{1-B(x)} \] 的形式 要用拆系数fft,直接把之前的代码复制上就可以啦 #include <iostream…
HDOJ(HDU).2660 Accepted Necklace (DFS) 点我挑战题目 题意分析 给出一些石头,这些石头都有自身的价值和重量.现在要求从这些石头中选K个石头,求出重量不超过W的这些石头的最大价值是多少? 类似于之前讨论到的数字选不选的问题,此处面临的情况是石头选不选,若选进行一个dfs,若不选择进行另外一个dfs.考虑递归边界: 1.当选够了K个的时候,终止递归: 2.当当前重量大于W的时候,终止递归: 3.当所选石头的下标(代码中的pos)超过石头数量的时候,终止递归: 若…
题目链接 :http://acm.hdu.edu.cn/showproblem.php?pid=6030 Problem Description Little Q wants to buy a necklace for his girlfriend. Necklaces are single strings composed of multiple red and blue beads. Little Q desperately wants to impress his girlfriend,…
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2660 Accepted Necklace Description I have N precious stones, and plan to use K of them to make a necklace for my mother, but she won't accept a necklace which is too heavy. Given the value and the weight…
Problem Description I have N precious stones, and plan to use K of them to make a necklace for my mother, but she won't accept a necklace which is too heavy. Given the value and the weight of each precious stone, please help me find out the most valu…
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5730 [题目大意] 给出一个数组w,表示不同长度的字段的权值,比如w[3]=5表示如果字段长度为3,则其权值为5,现在有长度为n的字段,求通过不同拆分得到的字段权值乘积和. [题解] 记DP[i]表示长度为i时候的答案,DP[i]=sum_{j=0}^{i-1}DP[j]w[i-j],发现是一个卷积的式子,因此运算过程可以用FFT优化,但是由于在计算过程中DP[j]是未知值,顺次计算复杂度是O(…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5730 可以用分治FFT.但自己只写了多项式求逆. 和COGS2259几乎很像.设A(x),指数是长度,系数是方案. \( A(x)^{k} \) 的 m 次项系数表示 k 个连续段组成长度为 m 的序列的方案数. \( B(x)=1+F(x)+F^{2}(x)+F^{3}(x)+... \) \( B(x) = \frac{1}{1-F(x)} \)(通过计算B(x)的逆来看出这个式子) 然后多项式求逆…
Accepted Necklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2474    Accepted Submission(s): 973 Problem Description I have N precious stones, and plan to use K of them to make a necklace f…
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5730 DP式:\( f[i] = \sum\limits_{j=1}^{i} f[i-j] * a[j] \) 因为没有给 \( f[0] \) 赋初值,所以在递归底层令 \( f[l] += a[l] \) 注意多组数据清空数组: 读入 \( s[i] \) 时要取模!! 代码如下: #include<iostream> #include<cstdio> #include<cstr…
http://acm.hdu.edu.cn/showproblem.php?pid=2660 f[v][u]=max(f[v][u],f[v-1][u-w[i]]+v[i]; 注意中间一层必须逆序循环. #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ][]; ],w[]; int main() { //freopen("a.txt",&qu…
题意:一段长为 i 的项链有 a[i] 种装饰方式,问长度为n的相连共有多少种装饰方式 分析:采用dp做法,dp[i]=∑dp[j]*a[i-j]+a[i],(1<=j<=i-1) 然后对于这种递推式,也就是dp[i]等于前j个dp数组和a数组的卷积,然后可看所有的 一看n是1e5,所以暴力超时,然后采用cdq分治加速,这种卷积递推通常采用cdq分治加速 cdq的话很简单了,就是先递归左边,算左对右的贡献,递归右边就行,一半一半更新 #include <cstdio> #inclu…
题意: 给出连续的1-n个珠子的涂色方法 a[i](1<=i<=n), 问长度为n的珠链共有多少种涂色方案 分析: 可以得到DP方程: DP[n] = ∑(i=1,n) (DP[n-i]*a[i]). 该方程为卷积形式,故 CDQ + FFT CDQ: 将 [l,r] 二分, 先得到[l,mid]的答案,再更新[l,mid]对[mid+1,r]的贡献.   对任意 DP[j](mid+1 <= j <= r), [l,mid] 对其贡献为 ∑(i=l,mid) (DP[i]*a[j…
题目链接 dp[n] = sigma(a[i]*dp[n-i]), 给出a1.....an, 求dp[n]. n为1e5. 这个式子的形式显然是一个卷积, 所以可以用fft来优化一下, 但是这样也是会超时的. 所以可以用cdq分治来优化. cdq分治就是处理(l, mid)的时候, 将dp[l]...dp[mid]对dp[mid+1]...dp[r]做的贡献都算出来. #include <bits/stdc++.h> using namespace std; #define pb(x) pus…
Description 给出长度分别为1~n的珠子,长度为i的珠子有a[i]种,每种珠子有无限个,问用这些珠子串成长度为n的链有多少种方案 题解: dp[i]表示组合成包含i个贝壳的项链的总方案数 转移:dp[i]=Σdp[i-j]*a[j](1<=j<=i) #include <bits/stdc++.h> using namespace std; #define dob complex<double> #define rint register int #defin…
题目链接 \(Description\) 有\(n\)个长度分别为\(1,2,\ldots,n\)的珠子串,每个有\(a_i\)种,每种个数不限.求有多少种方法组成长度为\(n\)的串.答案对\(313\)取模. \(Solution\) 令\(f_i\)表示组成长度为\(i\)的串的方案数,可以得到递推式:\[f_i=\sum_{j=0}^{i-1}a_{i-j}f_j,\ f_0=1\]或者\(f_i=\sum_{j=1}^{i-1}a_{i-j}f_j+a_i\). 这样暴力是\(O(n^…
题意:一个项链用n个珠子构成,是一个条而不是一个环,由红和蓝两种颜色构成,要求以任意点为起点向后的素数个珠子中,保证红颜色的大于等于蓝颜色的,问你有多少种方案满足,范围:n(2≤n≤1018) 推导过程参考链接:https://blog.csdn.net/nobleman__/article/details/78345142 我们知道最小的素数就是2了,由于考虑到是从任意一点开始,如果到了某一点往后没有两个的话就直接符合了,所以在n = 1的情况下,答案为2,也就是一个红,或一个蓝,首先我们可以…
大致题意: 一条长度为n的项链,由红色珠子和蓝色珠子(分别用1和0表示)组成,在连续的素数子段中,红色珠子的个数不能少于蓝色珠子.问组成这个项链有多少种方案,求方案数模1000000007 分析: 首先我们看看边界情况n=2 01 10 11 有如上3种情况 再观察一下n=3的情况 011 101 111 110 这四个方案中有3种方案(011,101,111)有关联,n=2的情况再加一个1,结尾为1,那么肯定也有为结尾为0的情况.我们继续推测 n=4 0111 1011 1111 1101 0…
1219 遍历计数. #include<bits/stdc++.h> #define QAQ 0 using namespace std; ]; ]; int main(){ )){ memset(cnt,,sizeof(cnt)); int l=strlen(a); ;i<l;i++){ cnt[a[i]]++; } for(int i='a';i<='z';i++){ printf("%c:%d\n",i,cnt[i]); } printf("\n…
写在前面的.. 感觉自己是应该学点新东西了.. 所以就挖个大坑,去学FFT了.. FFT是个啥? 挖个大坑,以后再补.. 推荐去看黑书<算法导论>,讲的很详细 例题选讲 1.UOJ #34. 多项式乘法 这是FFT最裸的题目了 FFT就是拿来求这个东西的 没啥好讲的,把板子贴一下吧.. #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #inc…
CDQ学习资料 day1cdq分治相关 CDQ的IOI论文 1.优化斜率dp 左边对右边影响维护一个凸包解决 需要知识:①凸包②斜率dp 题目:√ HDU3842 Machine Works   HYSBZ 1492 货币兑换Cash 2.三维/多维偏序 cdq降维,剩下用数据结构维护. 需要知识:①LIS②偏序关系③二维线段树/树状数组 题目:陌上花开(此题目前找不到) Pinball Game3D 3.CDQ+FFT/NTT 需要知识:①FFT②NTT 题目:HDU 5730 Shell N…
Necklace/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5727 Description SJX has 2*N magic gems. N of them have Yin energy inside while others have Yang energy. SJX wants to make a necklace with these magic gems for his beloved BHB. To avoid…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5727 Problem DescriptionSJX has 2*N magic gems. N of them have Yin energy inside while others have Yang energy. SJX wants to make a necklace with these magic gems for his beloved BHB. To avoid maki…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3091 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 327680/327680 K (Java/Others) Problem Description One day , Partychen gets several beads , he wants to make these beads a necklace . But not ever…
Necklace HDU - 3874  Mery has a beautiful necklace. The necklace is made up of N magic balls. Each ball has a beautiful value. The balls with the same beautiful value look the same, so if two or more balls have the same beautiful value, we just count…
Necklace Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2083    Accepted Submission(s): 747 Problem Description Mery has a beautiful necklace. The necklace is made up of N magic balls. Each ba…
Mery has a beautiful necklace. The necklace is made up of N magic balls. Each ball has a beautiful value. The balls with the same beautiful value look the same, so if two or more balls have the same beautiful value, we just count it once. We define t…
[题目链接]http://acm.hdu.edu.cn/showproblem.php?pid=5727 [题目大意] 现在有n颗阴珠子和n颗阳珠子,将它们阴阳相间圆排列构成一个环,已知有些阴珠子和阳珠子不能放在相邻的位置,否则这颗阳珠子就会失去功效,输出最少失去能量的阳珠子数目 [题解] 对于阴珠子固定的排列方式,可以用算出阳珠子能够不失去能量就能够放置的位置,将这种关系看成一条边,进行二分图匹配,就可以得不失去能量的阳珠子的最大值,显然就可以获得最少失去能量的数目. 注意在此题中,不知道阴珠…
Necklace Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 327680/327680 K (Java/Others)Total Submission(s): 709    Accepted Submission(s): 245 Problem Description One day , Partychen gets several beads , he wants to make these beads a necklace…