POJ1745 Divisibility(dp)

POJ 1745 / UVa 10036 Divisibility (同余定理,DP,经典题目) 题目链接: POJ http://poj.org/problem?id=1745 UVa OJ https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=977 注:两个OJ系统要求不同 ,UVa 需要键入测试组数,POJ 则没有。 阅读详情

Divisibility
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 11053 Accepted: 3953

Description

Consider an arbitrary sequence of integers. One can place + or - operators between integers in the sequence, thus deriving different arithmetical expressions that evaluate to different values. Let us, for example, take the sequence: 17, 5, -21, 15. There are eight possible expressions: 17 + 5 + -21 + 15 = 16 
17 + 5 + -21 - 15 = -14 
17 + 5 - -21 + 15 = 58 
17 + 5 - -21 - 15 = 28 
17 - 5 + -21 + 15 = 6 
17 - 5 + -21 - 15 = -24 
17 - 5 - -21 + 15 = 48 
17 - 5 - -21 - 15 = 18 
We call the sequence of integers divisible by K if + or - operators can be placed between integers in the sequence in such way that resulting value is divisible by K. In the above example, the sequence is divisible by 7 (17+5+-21-15=-14) but is not divisible by 5. 

You are to write a program that will determine divisibility of sequence of integers. 

Input

The first line of the input file contains two integers, N and K (1 <= N <= 10000, 2 <= K <= 100) separated by a space. 
The second line contains a sequence of N integers separated by spaces. Each integer is not greater than 10000 by it's absolute value. 

Output

Write to the output file the word "Divisible" if given sequence of integers is divisible by K or "Not divisible" if it's not.

Sample Input

4 7
17 5 -21 15

Sample Output

Divisible



给一个长度为n的数组,自己可以加减运算,问能不能被k整除。


读入的时候处理,dp[i][j] == 1代表可以被k整除。


状态转移方程:dp[i][(j + num[i]) % k],dp[i][(k + j - num[i]) % k] ,表示加上或减去第i个数,所得数取模能否为j。


AC代码:


#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
using namespace std;
const int maxn = 1e4 + 5;
int main(int argc, char const *argv[])
{
	int n, k;
	while(cin >> n >> k) {
		int dp[maxn][101] = {0}, num[maxn];
		for(int i = 0; i < n; ++i) {
			cin >> num[i];
			if(num[i] < 0) num[i] = -num[i];
			num[i] %= k;
		}
		dp[0][num[0]] = 1;
		for(int i = 1; i < n; ++i)
			for(int j = 0; j <= k; ++j)
				if(dp[i - 1][j]) {
					dp[i][(j + num[i]) % k] = 1;
					dp[i][(k + j - num[i]) % k] = 1;
				}
		if(dp[n - 1][0]) cout << "Divisible" << endl;
		else cout << "Not divisible" << endl;
	}
	return 0;
}


无限维李代数局部与2-局部1/2-导子:从概念到Witt代数实例解析 在抽象代数与数学物理中,李代数是描述对称性的基本结构,而导子则是刻画其微分性质的核心算子。从经典的导子概念出发,通过引入“局部”与“分数阶”两个关键推广,形成了局部导子、2-局部导子以及1/2-导子等重要研究方向。这些推广不仅深化了对无限维李代数(如Witt代数、Virasoro代数)复杂结构的理解,其研究方法和结论也为共形场论、可积系统等物理理论提供了数学基础。本文聚焦于无限维李代数上局部与2-局部1/2-导子的系统研究,通过拆解核心概念、剖析典型代数结构,并以Witt代数为实例,详细演示了从全局1/2- 阅读详情

相关推荐

IEC61850建模实战:从标准解读到ICD文件生成

本文详细介绍了IEC61850建模的实战过程,从标准解读到ICD文件生成,涵盖了变电站自动化系统的结构化数据模型设计。通过分层结构、标准服务映射和XML文件解析,帮助读者掌握电力系统智能电子设备的标准化建模方法,提升工程实施效率。

weixin_30823001的博客 424

POJ1745Divisibility【dp】

Divisibility Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11053   Accepted: 3953 Description Consider an arbitrary sequence of integ

走一步再走一步 734

用C#和MQTTnet在WinForm里做个简易物联网监控后台(附完整源码)

本文详细介绍了如何使用C#和MQTTnet库在WinForm中构建一个简易物联网监控后台。通过实战案例,包括环境配置、MQTT服务端实现、客户端监控功能及高级优化技巧,帮助开发者快速搭建高效的物联网监控系统,适用于工业自动化和智能家居场景。

weixin_29540599的博客 395

poj 1745 Divisibility 【DP】

Divisibility Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11044   Accepted: 3949 Description Consider an arbitrary sequence of integers. One can place + o

世界很大 655

csp-j/s

CSP-J/S 是中国计算机学会(CCF)主办的 ‌‌(Certified Software Professional Junior/Senior),是信息学奥赛(NOI)体系的入门级选拔考试,也是国内最具权威性的青少年编程能力认证之一。

gxyxxrYYDS的博客 2052

苍穹外卖项目面试总结话术

美食速递这个项目最初是我参与制作的大创项目,是一款为中南学生提供校园外卖送至宿舍服务的软件,包含系统管理后台和小程序端两部分。其中系统管理后台主要提供给食堂内部员工使用,可以对食堂各个窗口、员工、订单、菜品等进行维护管理;小程序端可以在线浏览菜品、添加购物车、下单等,由学生兼职做跑腿送餐上门服务。这是个前后端分离的项目,我主要是负责后端的用户登录、员工管理,菜品管理,订单管理模块的编码实现。

qq_45195447的博客 1万+

【DP】POJ-1745 Divisibility

给出n个有正有负的数字,在它们中间添加加号或者减号,问能否得到一个表达式的值除得尽K。

JSure的代码库 1171

从零上手HiAgent:构建能听懂指令的智能体框架实战指南

智能体(Agent)作为人工智能领域的重要范式,正从传统的预设流程自动化转向以目标驱动的自主规划与执行。其核心原理在于利用大语言模型(LLM)作为决策大脑,通过任务规划、工具调用与记忆机制,将模糊的自然语言指令转化为可执行的工作流。这一技术显著提升了人机协作的效率和自然度,其价值在自动化办公、数据分析与智能流程编排等场景中尤为突出。本文聚焦于HiAgent这一具体框架,深入解析其作为智能体开发平台的核心架构,涵盖规划器、执行器、工具集等关键组件,并提供从环境配置、自定义工具开发到复杂任务链构建的完整工程实践

weixin_29266007的博客 921

POJ 1745 Divisibility【DP】

Language:Default Divisibility Time Limit:1000MS Memory Limit:10000K Total Submissions:8396 Accepted:2909 Description Consider an arbitrary sequence of...

dianxuanzhi1019的博客 139

基于AnimeGAN模型生成宫崎骏风格动漫照片

用于动画风格纹理和线条转换的灰度样式丢失;新颖的颜色重建损失,以保留内容图像的颜色;新的灰度对抗损失防止生成的图像从显示为灰度图像;使用深度可分卷积和反向残块的轻量级生成器,以实现更快的传输。实验表明,AnimeGAN可以对真实世界的照片进行变换场景动画风格的图像与高质量的动画视觉效果和显著优于最先进的风格化方法。# 生成宫崎骏风格图片 model = hub . Module('animegan_v1_hayao_60' , use_gpu = True)images:输入的图片数据。

CSDN 精品推荐 3634

C#串口通信从入门到精通(27)——高速通信下解决数据处理慢的问题(20ms以内)

本文介绍如何在高速通信情况下解决串口接收的数据来不及处理的问题,由高级工程师多年经验总结而成,绝对是串口领域的实战经验!

qq_34059233的博客 6822

POJ 1745 Divisibility DP

POJ:http://poj.org/problem?id=1745 A完这题去买福鼎肉片,和舍友去买滴~舍友感慨“这一天可以卖好几百份,每份就算赚一块钱。。那么一个月。。一年。。。” 我说“那我们以后去卖这个吧,饿了还能自己煮着吃” 哈哈,一群天真的少年呀~~~~ 说正事~ ------------------------------------------------华...

weixin_30563319的博客 100

芒果YOLO11改进44:主干Backbone篇之MobileViT::结合最新 ICLR2022 顶会|轻量通用的MobileViT结构(一)Transformer,轻量级、通用且移动友好的视觉转换

MobileViT::结合最新 ICLR2022 顶会|轻量通用的MobileViT结构(一)Transformer,轻量级、通用且移动友好的视觉转换

包括YOLOv5、YOLOv7、YOLOv8等模型改进 379

POJ Problem 1745 Divisibility 【dp】

Divisibility Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11461   Accepted: 4100 Description Consider an arbitrary sequence of integers. One can place +

博客已搬迁到http://www.cnblogs.com/cniwoq/ 264

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

POJ 1745 Divisibility (DP)

Divisibility Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 11452   Accepted: 4097 Description Consider an arbitrary sequence of integers. One can place + o

Calm微笑 441

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

POJ 1745 Divisibility --dp

Description Consider an arbitrary sequence of integers. One can place + or - operators between integers in the sequence, thus deriving different arithmetical expressions that evaluate to diffe...

lanshan1111的博客 158

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

poj 1745 Divisibility(DP + 数学)

poj 1745 Divisibility(DP + 数学)

1990

POJ - 1745 Divisibility【DP好题】

Consider an arbitrary sequence of integers. One can place + or - operators between integers in the sequence, thus deriving different arithmetical expressions that evaluate to different values. Let us,...

slass-mot-odet 349

POJ1745Divisibility(dp)

Description Consider an arbitrary sequence of integers. One can place + or - operators between integers in the sequence, thus deriving different arithmetical expressions that evaluate to different va

菜鸟的自我修养 314

poj 1745 Divisibility dp

点击打开题目链接 题意:给出n个数字,让你在这n个数字之间加上加号和减号,问最后能不能得到一个数字,使它能被k整除。 思路:dp,把每个数字处理后可能得到的结果保存下来,如果能得到,dp值就是1,否则就是0.需要注意的是,每个得到的值必须是由前面的所有数字进行加减得到的,所以每次状态转移的时候只能把新得到的状态存下来,而之前的状态都抛弃,因为之前得到的状态都是只由前i个数字得到

cstdio_hao的专栏 469

DP poj1745 Divisibility

题目地址链接:http://poj.org/problem?id=1745 题目: Divisibility Description Consider an arbitrary sequence of integers. One can place + or - operators between integers in the sequence, thus d

开溜老A 459

poj 1745 Divisibility dp

题意: 给你n个数每个数可以取正负,问是否存在一种情况使得最后的公式%k的值等于0 分析: 因为k 那么dp【i】【j】=max(dp[i-1][(j-a[i]+m)%m],dp[i-1][(j+a[i])%m]); ACcode: #include #include #include #include #define maxn 10007 #define inf 0x3f3f

MY Blog 364

poj 1745 Divisibility dp

Divisibility Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9693   Accepted: 3380 Description Consider an arbitrary sequence of integers. One can place + or

Clearlemon 606

poj - 1745 - Divisibility(dp)

题意:一个长为 N 的序列(每个元素的绝对值不超过10000),为其中间的 N - 1 个位置添加 "+" 或者 "-",问能否使得最后的数能被 K 整除(1 题目链接:http://poj.org/problem?id=1745 ——>>这题和poj - 1722很像,不同点在于这题的 N 变大了100倍,但是,相应地,dp的第二维其实变小了100倍(可对K取模)。。       状态:

无节操 1417

poj 1745 Divisibility(DP)

Divisibility Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9562   Accepted: 3329 Description Consider an arbitrary sequence of integers. One can place + or -

WEYuLi的专栏 1010
上一篇: Codeforces Round #251 (Div. 2) 439D Devu and his Brother(脑洞)
下一篇: HDOJ5305 Friends(dfs)
GKHack
博客等级 码龄12年 48粉丝 291原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值