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太短需要处理的数据较长 下面是 ...
随机推荐
- h5跳转到app的实现
随着业务的增加,可能存在这么一种需求,就是需要从h5中直接跳转到app.如果没有安装app的话,则提示到应用市场或者app store下载安装.不过问题就在这个地方,单纯的用h5是没有方法判断是否安装 ...
- 最新版的stm32f1xx.h文件中取消了u8, u16, u32的类型定义
使用芯片stm32f103zet6和stm32l151c8t6,在移植程序时发现,编译器提示u8未定义: 在Keil MDK 开发环境里,st定义无符号32位整形数据有很多种表示方法: 1 unsig ...
- Tomcat7 调优及 JVM 参数优化
Tomcat 的缺省配置是不能稳定长期运行的,也就是不适合生产环境,它会死机,让你不断重新启动,甚至在午夜时分唤醒你.对于操作系统优化来说,是尽可能的增大可使用的内存容量.提高CPU 的频率,保证 ...
- 破解使用SMB协议的Windows用户密码:acccheck
一.工作原理 Acccheck是一款针对微软的SMB协议的探测工具(字典破解用户名和密码),本身不具有漏洞利用的能力. SMB协议:SMB(Server Message Block)通信协议主要是作为 ...
- 20145209刘一阳 《网络对抗》Exp7 网络欺诈技术防范
20145209刘一阳 <网络对抗>Exp7 网络欺诈技术防范 一.应用SET工具建立冒名网站 要让冒名网站在别的主机上也能看到,需要开启本机的Apache服务,并且要将Apache服务的 ...
- 苏州Uber优步司机奖励政策(8月31日至9月6日)
当周最新司机奖励(8月31日至9月6日) 滴滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http: ...
- 利尔达NB-IOT模组Coap数据AT+NMGS发送时返回-513的原因
1. 利尔达NB-IOT模组使用AT+NMGS发送数据,返回-513的问题,大致有3种可能性,在硬件上,模组的射频电路分为A型和B型模组,所以烧写固件的时候,也要分为A和B型固件,如果烧写反了,那么R ...
- Clojure基础课程2-Clojure中的数据长啥样?
本文来自网易云社区 作者:李诺 " Clojure is elegant and pragmatic; it helps me focus more on solving business ...
- Qt-网络与通信-获取本机网络信息
在网络应用中,经常需要获取本机主机名和IP地址和硬件地址等信息.运用QHostInfo.QNetworkInterface.QNetworkAddressEntry可以获得本机的网络信息. 上运行截图 ...
- Selenium WebDriver(Python)API
1.通过示例介绍Selenium-WebDriver 一个简单的入门方法就是这个例子,它在Google上搜索术语“Cheese”,然后将结果页面的标题输出到控制台. java csharp pytho ...