Codeforces Round #297 (Div. 2) E Anya and Cubes

十一、学生信息管理系统(PyQt5+MySQL+PyMySQL模块实现) 学生信息管理系统(PyQt5+MySQL+PyMySQL模块实现) 阅读详情

E. Anya and Cubes
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Anya loves to fold and stick. Today she decided to do just that.

Anya has n cubes lying in a line and numbered from 1 to n from left to right, with natural numbers written on them. She also has kstickers with exclamation marks. We know that the number of stickers does not exceed the number of cubes.

Anya can stick an exclamation mark on the cube and get the factorial of the number written on the cube. For example, if a cube reads 5, then after the sticking it reads 5!, which equals 120.

You need to help Anya count how many ways there are to choose some of the cubes and stick on some of the chosen cubes at most kexclamation marks so that the sum of the numbers written on the chosen cubes after the sticking becomes equal to S. Anya can stick at most one exclamation mark on each cube. Can you do it?

Two ways are considered the same if they have the same set of chosen cubes and the same set of cubes with exclamation marks.

Input

The first line of the input contains three space-separated integers n, k and S (1 ≤ n ≤ 25, 0 ≤ k ≤ n, 1 ≤ S ≤ 1016) — the number of cubes and the number of stickers that Anya has, and the sum that she needs to get.

The second line contains n positive integers ai (1 ≤ ai ≤ 109) — the numbers, written on the cubes. The cubes in the input are described in the order from left to right, starting from the first one.

Multiple cubes can contain the same numbers.

Output

Output the number of ways to choose some number of cubes and stick exclamation marks on some of them so that the sum of the numbers became equal to the given number S.

Sample test(s)
input
2 2 30
4 3
output
1
input
2 2 7
4 3
output
1
input
3 1 1
1 1 1
output
6
Note

In the first sample the only way is to choose both cubes and stick an exclamation mark on each of them.

In the second sample the only way is to choose both cubes but don't stick an exclamation mark on any of them.

In the third sample it is possible to choose any of the cubes in three ways, and also we may choose to stick or not to stick the exclamation mark on it. So, the total number of ways is six.



参考链接: http://www.cnblogs.com/qscqesze/p/4371851.html


给你n个数,k个魔法棒,s为所求的数,然后让你找有多少种方法,能够使的这n个数之和为s,其中一个魔法棒可以使的一个数变成他的阶乘


折半搜索
对于每一个数,都有三种策略,拿,不拿,使用魔法棒
那么我们就直接折半搜索然后扔进一个map里面,然后就查询


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>


#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)

#define eps 1e-8
typedef long long ll;

#define fre(i,a,b)  for(i = a; i <b; i++)
#define free(i,b,a) for(i = b; i >= a;i--)
#define mem(t, v)   memset ((t) , v, sizeof(t))
#define ssf(n)      scanf("%s", n)
#define sf(n)       scanf("%d", &n)
#define sff(a,b)    scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf          printf
#define bug         pf("Hi\n")

using namespace std;

#define INF 0x3f3f3f3f
#define N 30

ll a[N],n,k,s;
ll mid;

struct stud{
ll step,result;
}f[1111111];

ll p[20];
ll cnt;

map<ll,ll>mp[30];

void inint()
{
	int i,j;
	p[0]=1;
	p[1]=1;
	fre(i,2,20)
	 p[i]=p[i-1]*i;

}

void dfs(ll pos,ll num,ll va)
{
     if(num>k||va>s) return ;
	
		
     if(pos==mid+1)
	 {
	 	f[cnt].step=num;
	 	f[cnt++].result=va;
	 	return ;
	 }

    dfs(pos+1,num,va);
    dfs(pos+1,num,va+a[pos]);
    if(a[pos]<20)
		dfs(pos+1,num+1,va+p[a[pos]]);

}


void DFS(ll pos,ll num,ll va)
{
   if(num>k||va>s) return ;

   if(pos==n+1)
	{
	   mp[num][va]++;
	   return ;
	}

   DFS(pos+1,num,va);
    DFS(pos+1,num,va+a[pos]);
    if(a[pos]<20)
		DFS(pos+1,num+1,va+p[a[pos]]);

}


int main()
{
	ll i,j;
	inint();

	while(~scanf("%I64d%I64d%I64d",&n,&k,&s))
	{
		fre(i,1,n+1)
		  scanf("%I64d",&a[i]);

        fre(i,0,30)
		  mp[i].clear();

		mid=MID(0,n);
		cnt=0;

		dfs(1,0,0);

		DFS(mid+1,0,0);
        ll ans=0;

        fre(j,0,cnt)
          fre(i,0,k-f[j].step+1)
            ans+=mp[i][s-f[j].result];

    pf("%I64d\n",ans);
	}
	return 0;
}



DAMMFND: Domain-Aware Multimodal Multi-view Fake News Detection 虚假新闻的泛滥不仅严重阻碍了互联网社交媒体的健康发展,还在政治、经济和社会层面造成了实际危害,凸显了自动化虚假新闻检测的重要性(Zhou 等,2015;Cui 等,2019;Zhu 等,2022a;Li 等,2024c,b,a)。现有的虚假新闻检测方法通常聚焦于特定领域的新闻,例如健康或政治领域。然而,在现实世界中,社交媒体上的新闻往往跨越多个领域,这就要求现有的虚假新闻检测方法必须考虑多域泛化(Nan 等,2021;Qi 等,2019;Zhu 等,2022b)。 阅读详情

相关推荐

学习利用ce修改游戏生命参数

易语言代码 游戏的简陋界面 用ce查找存储这个1000即生命值的内存地址(得先附加到目标程序上,点击左上角那个电脑按钮) 看到有很多值为1000的,但哪个是生命值呢?真相只有一个 我们点击一下打我这个按钮,看下面的ce界面上地址为004A65C0处的值变了,所以这个就是我们要找的生命值 接下来我们对生命值进行修改,修改为99

zsd747289639的博客 5万+

Anya and Cubes

然后主函数里面还有个小细节,建一个数组f,记录1~19的阶乘,为什么是十九呢,因为大于等于19的数的阶乘已经超出S的数据范围了。这里定义两个函数 dfs 和 dfs2,dfs用于找前一半并且记录,dfs2用于求出方案数。但是,这样最大的情况下就要搜索3^25次,是一个特别大的数,肯定要超时。首先,我们想到的思路肯定是深搜,就是三种选择,选原数,不选和选阶乘。如果now>end,就是遍历完了,vis记录一下,结束。这里写四个参数,now,end,sum和used。如果sum>s,就是超过了,不满足,剪掉。

STY_fish_2012的博客 521

《Linux运维总结:Ubuntu22.04忘记root密码解决方案》

《Linux运维总结:Ubuntu22.04忘记root密码解决方案》

东城绝神 4459

【CF525E】Anya and Cubes(meet in middle)

点此看题面 大致题意: 在\(n\)个数中选任意个数,并使其中至多\(k\)个数\(x_i\)变为\(x_i!\),求使这些数和为\(S\)的方案数。 \(meet\ in\ middle\) 这应该是\(meet\ in\ middle\)一道比较板子的题目。 我们先对于一半的数,爆搜然后开\((k+1)\)个\(map\)统计使用\(!\)个数小于等于\(i\),和为\(j\)的方案数。 然后...

weixin_30404405的博客 262

基于禾赛32线雷达和Xsens MTi-G-710 组合导航模块,松灵Scout mini 底盘实现 Cartographer 3D 建图过程

地下车库 Cartongrapher 3D建图

yhy_yhy13053117的博客 3936

从ViT到CLIP:OpenAI如何用4亿张图‘教会’AI看懂世界?一次讲透对比学习与Prompt工程

本文深入解析OpenAI的CLIP模型如何通过4亿图文对的对比学习实现跨模态理解,详细探讨了对比学习、数据构建、模型架构及Prompt工程等核心技术。CLIP利用Transformer架构和精心设计的Prompt模板,在Zero-Shot分类、图像检索等场景展现出强大能力,为多模态AI应用开辟新方向。

weixin_27027459的博客 371

Codeforces525E Anya and Cubes(双向搜索)

题目 Source http://codeforces.com/contest/525/problem/E Description Anya loves to fold and stick. Today she decided to do just that. Anya has n cubes lying in a line and numbered from 1 to n f...

dengliugong3918的博客 177

告别纯代码:用Visual Studio为LabVIEW封装一个‘即插即用’的海康VisionMaster控件

本文介绍如何利用Visual Studio为LabVIEW封装一个‘即插即用’的海康VisionMaster控件,解决传统集成方式中的代码臃肿和维护困难问题。通过.NET控件封装核心功能,实现LabVIEW与VisionMaster的高效对接,显著提升工业自动化开发效率。

weixin_33744854的博客 504

CF525E Anya and Cubes

#include <bits/stdc++.h> #include <hash_map> #define MAXN 30 #define int long long using namespace std; inline int read() { int x=0,f=1; char ch=getchar(); while (ch<'0'||ch...

蒟蒻Steven_Meng的博客 296

技术美术个人笔记(十三)——Houdini金属弯曲模拟

最近接收到使用Houdini自动解算破损/砸坏/扭曲汽车的需求,以此文记录制作金属弯曲自动解算工具时使用的部分节点解析;

小谁的博客 2148

如何设计一个处理物联网设备数据流的后端系统。

设计一个处理物联网设备数据流的后端系统,需要综合考虑设备数据采集、传输、处理、存储等多个方面,保证系统能够处理海量数据,具备高可用性、扩展性和安全性。合理选择适当的技术架构和工具(如MQTT、Kafka、InfluxDB等),并确保系统能够灵活应对不断变化的业务需求和设备接入。

weixin_53227829的博客 838

Codeforces Round #297 (Div. 2) E题. Anya and Cubes (中途相遇法)

题目地址:Anya and Cubes 比赛的时候居然没想起中途相遇法。。。这题也是属于想起来就很简单系列。 中途相遇法也叫折半搜索。就是处理前一半,把结果储存起来,再处理后一半,然后匹配前一半存储的结果。 代码如下:#include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algo

scf0920 1424

30、模态组合规则在振动分析中的应用

本文详细介绍了模态组合规则在振动分析中的应用,重点讨论了绝对峰值叠加法(SRSS)和完全二次组合(CQC)的理论基础、应用场景及优缺点。通过具体工程实例,展示了模态组合规则在地震载荷下结构响应分析中的实际效果,并提供了应用步骤和注意事项,为结构设计和安全评估提供了科学依据。

nice1的博客 221

Codeforces Round #297 (Div. 2) 525E Anya and Cubes(dfs)

E. Anya and Cubes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Anya loves to fold and stick. Today she d

GKHack's Blog 992

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

【Codeforces Round #297 (Div. 2)】Codeforces 525E Anya and Cubes

dfs枚举+中途相遇法

YHaX的博客 640

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Codeforces Round #297 (Div. 2) E. Anya and Cubes (双向DFS)

首先思考最暴力的方法: 我们用DFS直接搜索所有可能解, 那么对于每一层,有3种决策: 不选这个数, 选择这个数, 选择这个数的阶乘。  递归深度最大25, 时间复杂度O(3^25), 太大了, 要想办法降低时间复杂度。   还记得之前的简化版吗?  我们在四个集合中每个集合选择一个数字相加,问是否等于一个数S, 我们的方法是预处理两个集合中所有的情况,然后二分。  该题也可以采取相同的策略: 进

AC_Arthur的专栏 947

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

Codeforces Round #297 (Div. 2) E. Anya and Cubes

中途相遇法。。分成两半计算。。。 #include #include #include #include #include #include #include #include #include #include #include #include #include #define maxn 2005 #define maxm 300005 #define eps 1e

yysys 452

Codeforces Round #297 (Div. 2)---E. Anya and Cubes

Anya loves to fold and stick. Today she decided to do just that.Anya has n cubes lying in a line and numbered from 1 to n from left to right, with natural numbers written on them. She also has k sticke

Alex 1121

Codeforces Round #297(div 2) E. Anya and Cubes (双向dp)

题目链接 题目 【题目大意】:给你nnn个数和kkk根魔法棒,魔法棒可以把数字变成它的阶乘,比如5+魔法棒=5!=1205+魔法棒=5!=1205+魔法棒 = 5!= 120。然后给你一个S,问:用这nnn个数,顶多有kkk个数可以变成阶乘,最后有几种方案可以凑出S这个数 (1≤n≤25,0≤k≤n,1≤S≤10161≤n≤25,0≤k≤n,1≤S≤10161≤n≤25, 0≤k≤n...

王大凤的博客 244

Codeforces Round #297 (Div. 2)E. Anya and Cubes 折半搜索

Codeforces Round #297 (Div. 2)E. Anya and Cubes Time Limit: 2 SecMemory Limit: 512 MBSubmit: xxx Solved: 2xx 题目连接 http://codeforces.com/contest/525/problem/E Description Anya lov...

weixin_30315905的博客 84

Codeforces Round #297 (Div. 2) E - Anya and Cubes

题解 #include using namespace std; typedef long long LL; int N, K; LL S; int a[26]; LL A[26]; map sum[26]; void dfs(int p, int k, LL s) { if(s > S || k > K) return; if(p == N / 2) { sum[k][s] ++;

Step by step 509

[Codeforces Round #297 Div. 2] E. Anya and Cubes

http://codeforces.com/contest/525/problem/E 学习了传说中的折半DFS/双向DFS 先搜前一半数,记录结果,然后再搜后一半数,匹配之前结果。 1 #include<algorithm> 2 #include<iostream> 3 #include<cstring> 4 #include&l...

weixin_34062329的博客 57

Codeforces Round #297 (Div. 2)E. Anya and Cubes(折半搜索)

E. Anya and Cubes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Anya loves to fold and stick. Today she d

Rain 468

中途相与法(Codeforces Round #297 (Div. 2)E - Anya and Cubes )

E. Anya and Cubes time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Anya loves to fold and stick. Today she decided to

龙崎的专栏 635

Codeforces Round #297 (Div. 2) 525E Anya and Cubes(折半查找+map)

题目链接 题意:给出n个棍子, k个魔法棒, 目标数s. 魔法棒可以使得棍子长度变为棍子长度的阶乘, 问木棒和为s的方案数. 预处理求出阶乘, 根据s范围可知木棒最长是18, 而后进行dfs, dfs时, 分为三种情况, 取这根木棒, 不取这根木棒, 以及取这根木棒的阶乘. 进行两次dfs, 折半存储结果.,这次map开了两维,其实这种思想用的很多,比如区间求中位数,以后多多注意下。 详

城南的花 698
上一篇: HDU 4734 F(x) (数位dp+ 记忆化)
下一篇: Codeforces Round #297 (Div. 2) D Arthur and Walls(bfs)
左眼皮跳跳~
博客等级 码龄13年 17粉丝 400原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值