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太短需要处理的数据较长 下面是 ...
随机推荐
- go加密算法:CBC对称加密(一)--DES
package main import ( "bytes" //"crypto/aes" "crypto/cipher" "cry ...
- memcache类的扩展函数
Memcache — Memcache类 /****连接****/1.Memcache::connect – 创建一个Memcache对象语法:bool Memcache::connect ( str ...
- Mac下PHP的环境搭建
* 前段时间手欠 ... 入手了一个二手的Macbook pro ! 配置挺高的 16款13寸的基本顶配了 ... 只差 硬盘不是1T的 ... 可以脑补一下配置了* 话说 不是所有程序猿都说 每个程 ...
- 如何用SQL语句处理缓慢变化维(渐变维,拉链表)SCD-2?
假设有一张居民维表,需要记录居民状态的变更历史,根据Kimball建模理论,设计居民维表如下: 另外在ODS中有居民信息的每日快照表(每天都记录一份居民的全量信息):O_USERINFO 如何将ODS ...
- openwrt利用openvpn两网互通
目录 创建证书文件服务器端配置防火墙配置客户端配置uvs-001(远端PC)uvs-002(网关下属设备)测试连接 创建证书文件 安装证书工具 opkg openvpn-easy-rsa 创建证书 b ...
- 利用谷歌浏览器断点调试js反向解析,解密
目标网站:https://www.aqistudy.cn/html/city_detail.html 点击按钮才会去后台请求数据, 第一步:将click打开, 第二步:找个后台请求数据的url h ...
- C# 获取UTC 转换时间戳为C#时间
获取UTC /// <summary> /// 获取时间戳 /// </summary> /// <returns>UTC</returns> publ ...
- Django中的模型继承
1.使用最原始的方式继承 class Animal(models.Model): name = models.CharField(max_length=20) age = models.Integer ...
- python中通过datetime获取UTC时间ISO格式
一个热点统计需求,需要限定一个时间范围,计算出该范围内的热点事件,相关数据则以UTC标准时间的ISO时间格式存在mongodb中,和服务器设置的时区UTC+8并不一致. 为了解决这个问题,直觉反应是在 ...
- BZOJ1968_COMMON约数研究_KEY
题目传送门 BZOJ水题,for i=1~N,答案加上N/i即可 ANS=∑N/i(i∈{1~N}) code: /****************************************** ...