数学基础(卷积,FFT,FWT,FMT,鸽巢原理,群论,哈里亚余数,哈里亚计数定理,组合数学,LVG定理,期望DP,期望点贡献问题)

练习题:

A - Necklace of Beads

Beads of red, blue or green colors are connected together into a circular necklace of n beads ( n < 24 ). If the repetitions that are produced by rotation around the center of the circular necklace or reflection to the axis of symmetry are all neglected, how many different forms of the necklace are there?

Input

The input has several lines, and each line contains the input data n.

-1 denotes the end of the input file.

Output

The output should contain the output data: Number of different forms, in each line correspondent to the input data.

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.

Input

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

Input
3 2
1 2 3
Output
2 3 4 5 6
Input
5 5
1 1 1 1 1
Output
5
Input
3 3
3 5 11
Output
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 第十八天的更多相关文章

  1. SCNU ACM 2016新生赛决赛 解题报告

    新生初赛题目.解题思路.参考代码一览 A. 拒绝虐狗 Problem Description CZJ 去排队打饭的时候看到前面有几对情侣秀恩爱,作为单身狗的 CZJ 表示很难受. 现在给出一个字符串代 ...

  2. SCNU ACM 2016新生赛初赛 解题报告

    新生初赛题目.解题思路.参考代码一览 1001. 无聊的日常 Problem Description 两位小朋友小A和小B无聊时玩了个游戏,在限定时间内说出一排数字,那边说出的数大就赢,你的工作是帮他 ...

  3. acm结束了

    最后一场比赛打完了.之前为了记录一些题目,开了这个博客,现在结束了acm,这个博客之后也不再更新了. 大家继续加油!

  4. 关于ACM的总结

    看了不少大神的退役帖,今天终于要本弱装一波逼祭奠一下我关于ACM的回忆. 从大二上开始接触到大三下结束,接近两年的时间,对于大神们来说两年的确算不上时间,然而对于本弱来说就是大学的一半时光.大一的懵懂 ...

  5. 第一届山东省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 ...

  6. 第一届山东省ACM——Balloons(java)

    Description Both Saya and Kudo like balloons. One day, they heard that in the central park, there wi ...

  7. ACM之鸡血篇

    一匹黑马的诞生 故事还要从南京现场赛讲起,话说这次现场赛,各路ACM英雄豪杰齐聚南京,为争取亚洲总舵南京分舵舵主之职位,都使出了看 家本领,其中有最有实力的有京城两大帮清华帮,北大帮,南郡三大派上交派 ...

  8. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  9. acm 1002 算法设计

    最近突然想往算法方向走走,做了做航电acm的几道题 二话不说,开始 航电acm 1002 题主要是处理长数据的问题,算法原理比较简单,就是用字符数组代替int,因为int太短需要处理的数据较长 下面是 ...

随机推荐

  1. python中mysql主从同步配置的方法

    1)安装mysql ubuntu中安装一台mysql了,docker安装另外一台mysql 获取mysql的镜像,主从同步尽量保证多台mysql的版本相同,我的ubuntu中存在的mysql是5.7. ...

  2. django的Request-7

    目录 1. 从url中获取截取 2. QueryDict (1). QueryDict.get(key, [default]) (2). QueryDict.getlist(key, [default ...

  3. 《JQuery常用插件教程》系列分享专栏

    <JQuery常用插件教程>已整理成PDF文档,点击可直接下载至本地查阅https://www.webfalse.com/read/201719.html 文章 使用jquery插件实现图 ...

  4. %.*lf控制输出长度

    #include<stdio.h> int main(){    int a,b,c;    while(scanf("%d%d%d",&a,&b,&a ...

  5. [Real World Haskell翻译]第21章 使用数据库

    第21章 使用数据库 从网络论坛到播客采集软件甚至备份程序的一切频繁地使用持久存储的数据库.基于SQL的数据库往往是相当方便:速度快,可扩展从微小到巨大的尺寸,可以在网络上运行,经常帮助处理锁定和事务 ...

  6. vue跨域访问

    第一次创建vue项目,画完静态页面一切顺利,准备和后台进行联调,问题来了,无论怎么调试使用Axios,jQuary还是使用原生的Ajax请求都访问不通(前提条件,另外一个人的电脑当成服务器,进行访问) ...

  7. Developing iOS 8 Apps with Swift (stanford)

    https://www.youtube.com/watch?v=JkiB8Zwk-9Q&index=2&list=PLcX0opNQliFl0RTGbY9HHWCFg0Q8_fIF4

  8. xmind打开文件报错

    可以尝试使用导入 文件——导入 选择此方式打开即可.

  9. 实现动态的XML文件读写操作(依然带干货)

    前言 最近由于项目需求,需要读写操作XML文件,并且存储的XML文件格式会随着导入的数据不同而随时改变(当然导入的数据还是有一定约束的),这样我们要预先定义好XML文件的格式就不太现实了,如何实现不管 ...

  10. 北京Uber优步司机奖励政策(12月31日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...