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太短需要处理的数据较长 下面是 ...
随机推荐
- 如何使用git命令从github上取得项目
首先我们要安装git, git官网:https://git-scm.com/点击打开链接 拉取项目步骤详解 新建文件夹,最好取为项目英文名***Project 进入文件夹,空白处右键,选择git Ba ...
- STM32(1)——使用Keil MDK以及标准外设库创建STM32工程
转载来自:http://emouse.cnblogs.com 1.1 开发工具与开发环境 1. 软件版本 本节所使用Keil MDK 为目前的最新版V4.21.其他版本差别不大,读者可以根据自己使用的 ...
- Ruby中类的进阶(继承,private, public, protect)
类中的public,protect,private public method class Point def test end end 这样定义的test方法就是一个public方法可以在类内外使用 ...
- [原创]用python实现系统状态监测和故障转移
#coding: utf-8 import socket import select import time import os import threading def ser(): s = soc ...
- Prism for WPF 搭建一个简单的模块化开发框架(一)
原文:Prism for WPF 搭建一个简单的模块化开发框架(一) 最近闲来无事又想搞搞WPF..... 做个框架吧,可能又是半途而废....总是坚持不下来 不废话了, 先看一下工程结构 布局大概是 ...
- 成都Uber优步司机奖励政策(1月29日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 【调试】Linux下超强内存检测工具Valgrind
[调试]Linux下超强内存检测工具Valgrind 内容简介 Valgrind是什么? Valgrind的使用 Valgrind详细教程 1. Valgrind是什么? Valgrind是一套Lin ...
- 使用CRF做命名实体识别(三)
摘要 本文主要是对近期做的命名实体识别做一个总结,会给出构造一个特征的大概思路,以及对比所有构造的特征对结构的影响.先给出我最近做出来的特征对比: 目录 整体操作流程 特征的构造思路 用CRF++训练 ...
- connect by 语句
create table tb_menu( id number(10) not null, --主键id titlevarchar2(50), --标题 parent number(10) --par ...
- http tcp udp
HTTP连接 1.HTTP协议即超文本传送协议(Hypertext Transfer Protocol ),是Web联网的基础,也是手机联网常用的协议之一,HTTP协议是建立在TCP协议之上的一种应用 ...