ACM 第十八天
数学基础(卷积,FFT,FWT,FMT,鸽巢原理,群论,哈里亚余数,哈里亚计数定理,组合数学,LVG定理,期望DP,期望点贡献问题)
练习题:
A - Necklace of Beads
Input
-1 denotes the end of the input file.
Output
Sample Input
4
5
-1
Sample Output
21
39
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include <iostream>
//#define long long ll
using namespace std; int gcd(int x,int y)
{
if(x%y==) return y;
else return (gcd(y,x%y));
}
int main()
{
int n;
long long ans;
while(~scanf("%d",&n) && n!=-)
{
if(n<=) //注意n没有最小值范围哦
{
printf("0\n");
continue;
}
ans=;
for(int i=; i<=n; i++)
ans+=pow(, gcd(i,n));//旋转
if(n%) //翻转
{
ans+=n*pow(,n/+);
}
else
{
ans+=(n/)*pow(,n/);
ans+=(n/)*pow(,n/+);
}
ans=ans/(*n);
printf("%lld\n",ans);
}
return ;
}
C - Thief in a Shop
A thief made his way to a shop.
As usual he has his lucky knapsack with him. The knapsack can contain k objects. There are n kinds of products in the shop and an infinite number of products of each kind. The cost of one product of kind i is ai.
The thief is greedy, so he will take exactly k products (it's possible for some kinds to take several products of that kind).
Find all the possible total costs of products the thief can nick into his knapsack.
The first line contains two integers n and k (1 ≤ n, k ≤ 1000) — the number of kinds of products and the number of products the thief will take.
The second line contains n integers ai (1 ≤ ai ≤ 1000) — the costs of products for kinds from 1 to n.
Output
Print the only line with all the possible total costs of
stolen products, separated by a space. The numbers should be printed in
the ascending order.
Examples
3 2
1 2 3
2 3 4 5 6
5 5
1 1 1 1 1
5
3 3
3 5 11
9 11 13 15 17 19 21 25 27 33
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include <iostream>
#include<queue>
using namespace std;
const int maxn=1e3+; int a[maxn],dp[maxn*maxn]; int main()
{
int n,k;
cin>>n>>k;
for(int i=;i<=n;i++)
{
cin>>a[i];
}
sort(a+,a+n+);
n=unique(a+,a+n+)-(a+);
for(int i=;i<=n;i++)
{
a[i]=a[i]-a[];
}
for(int i=;i<=k*a[n];i++)
{
dp[i]=k+;
}
for(int i=;i<=n;i++)
{
for(int j=a[i];j<=k*a[i];j++)
{
dp[j]=min(dp[j],dp[j-a[i]]+);
}
}
for(int i=;i<=k*a[n];i++)
{
if(dp[i]<=k)
{
cout<<k*a[]+i<<" ";
}
}
cout<<endl;
return ; }
ACM 第十八天的更多相关文章
- SCNU ACM 2016新生赛决赛 解题报告
新生初赛题目.解题思路.参考代码一览 A. 拒绝虐狗 Problem Description CZJ 去排队打饭的时候看到前面有几对情侣秀恩爱,作为单身狗的 CZJ 表示很难受. 现在给出一个字符串代 ...
- SCNU ACM 2016新生赛初赛 解题报告
新生初赛题目.解题思路.参考代码一览 1001. 无聊的日常 Problem Description 两位小朋友小A和小B无聊时玩了个游戏,在限定时间内说出一排数字,那边说出的数大就赢,你的工作是帮他 ...
- acm结束了
最后一场比赛打完了.之前为了记录一些题目,开了这个博客,现在结束了acm,这个博客之后也不再更新了. 大家继续加油!
- 关于ACM的总结
看了不少大神的退役帖,今天终于要本弱装一波逼祭奠一下我关于ACM的回忆. 从大二上开始接触到大三下结束,接近两年的时间,对于大神们来说两年的确算不上时间,然而对于本弱来说就是大学的一半时光.大一的懵懂 ...
- 第一届山东省ACM——Phone Number(java)
Description We know that if a phone number A is another phone number B’s prefix, B is not able to be ...
- 第一届山东省ACM——Balloons(java)
Description Both Saya and Kudo like balloons. One day, they heard that in the central park, there wi ...
- ACM之鸡血篇
一匹黑马的诞生 故事还要从南京现场赛讲起,话说这次现场赛,各路ACM英雄豪杰齐聚南京,为争取亚洲总舵南京分舵舵主之职位,都使出了看 家本领,其中有最有实力的有京城两大帮清华帮,北大帮,南郡三大派上交派 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- acm 1002 算法设计
最近突然想往算法方向走走,做了做航电acm的几道题 二话不说,开始 航电acm 1002 题主要是处理长数据的问题,算法原理比较简单,就是用字符数组代替int,因为int太短需要处理的数据较长 下面是 ...
随机推荐
- Set的源码分析
Set的内部实现其实是一个Map.即HashSet的内部实现是一个HashMap,TreeSet的内部实现是一个TreeMap,LinkedHashSet的内部实现是一个LinkedHashMap. ...
- u-boot.2012.10makefile分析,良心博友汇总
声明:以下内容大部分来自网站博客文章,仅作学习之用1.uboot系列之-----顶层Makefile分析(一)1.u-boot.bin生成过程分析 2.make/makefile中的加号+,减号-和a ...
- java 写一个单例设计程序,打印出该对象的地址
class Test{ public static void main(String[] args) { singleton s1=singleton.getinstance(); singleton ...
- Highchart 饼图联动
感觉好久没有更新博客了,最近一直忙着毕业论文,紧接着就开始搭建数据库,实在抽不出时间写. 正好趁着做数据库,写一写关于Highchart里两个饼图之间的互动. 用到的数据比较大,我也懒得修饰了,涉及到 ...
- Windows下MySQL多实例运行(转)
关键字:Windows下MySQL多实例运行 阅读前注意事项: 1.有的版本的data目录不直接放在mysql安装目录下,有可能在:C:\ProgramData\MySQL\MySQL Server ...
- 【BZOJ3611】大工程(虚树,动态规划)
[BZOJ3611]大工程(虚树,动态规划) 题面 BZOJ Description 国家有一个大工程,要给一个非常大的交通网络里建一些新的通道. 我们这个国家位置非常特殊,可以看成是一个单位边权的树 ...
- 北京Uber优步司机奖励政策(4月1日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 苏州Uber优步司机奖励政策(3月28日~3月30日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- CentOS 7.2静默安装Oracle11g
Preface Today I'm gonna export some test data to another server.The source server is Windows ...
- 「日常训练」 Genghis Khan the Conqueror(HDU-4126)
题意 给定\(n\)个点和\(m\)条无向边(\(n\le 3000\)),需要将这\(n\)个点连通.但是有\(Q\)次(\(Q\le 10^4\))等概率的破坏,每次破坏会把\(m\)条边中的某条 ...