POJ1745Divisibility题解动态规划DP

747:Divisibility 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 v... 阅读详情
Divisibility
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 6514 Accepted: 2161

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

Source

状态:
d[i][j]表示前i个数mod k=j是否可达
状态转移方程:
d[i][j]=1    if(d[i-1][((j-a[i])%m+m)%m]||d[i-1][((j+a[i])%m+m)%m])
所以:
d[i][j]=d[i-1][((j-a[i])%m+m)%m]+d[i-1][((j+a[i])%m+m)%m]

边界:

d[1][(a[1]%m+m)%m]=1

 

代码:


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 则没有。 阅读详情

相关推荐

dfs+记忆化

由于回溯过程中会产生大量的重复计算,需要通过记忆化数组来记录在某个状态下(s字符位置和t字符位置)的值来简化计算。我个人理解,其实直接动态规划就行以leetcode115为例。

qq_41413211的博客 233

POJ---1745 Divisibility【动态规划】

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

菜鸟 404

电源完整性之仿真设计原理

电源完整性(Power Integrity),简称为PI,也就是大家平常听说的PI。PCB板上的电源设计也是非常重要的,不当的设计也会引起很重要的影响。所以电源完整性PI和信号完整性SI,是我们互连设计人员应该同等重视的问题。今天整理本人接触的电源完整性PI的一些原理,从不的角度去看PI,会有不同的理解,下面开始喽!!! 提到互连的电源设计,可能首先想到的电源分配网络(Power Distribution Nets),因为互连电源会有许多种,直流DC和交流AC,还有不同的电压调节模块(VRM)与不同的负载端

刘小同学的博客 7373

POJ - 1745 - Divisibility 【动态规划题2】

POJ - 1745 - Divisibility 【动态规划题2】 Description Consider an arbitrary sequence of integers. One can place + or - operators between integers in the sequence, thus deriving different arithmetical express...

iimT的独立博客 328

LVDS接口总结--(0)LVDS硬件电路接口

xilinx LVDS接口硬件总结

zidan1412的博客 9720

解决usbisp不识别无法烧录Atmega328P,Arduino不识别问题

如果使用Arduino IDE里面的烧录,可能会遇到一个问题,就是不识别国产这种廉价的USBISP 点击烧录引导程序,会遭遇到找不到USB设备的问题,选哪个都会提示找不到,比如选择USBasp could not find USB device with vid=0x16c0 pid=0x5dc vendor='www.fischl.de' product='USBasp' 因此,我们需要使用到progisp这一个软件的1.72版本 选择好芯片的型号后,调用编译好的HEX文...

arenascat的博客 7436

//dp动态规划//好题//poj1745//Divisibility

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,

lydia_ke的博客 424

光学仿真案例(4) 基于纳米微粒激发平面波的米氏散射FDTD仿真模拟

本案例展示了一个基于纳米粒子激发平面波的米氏散射仿真模型(mie scattering),计算其散射和吸收截面、局域场增强和远场散射分布,同时将截面和远场结果与解析解进行了比较,验证了仿真模拟的准确性。

q895235273的博客 3593

POJ 1745 Divisibility 01背包变式

POJ 1745 Divisibility 题目大意 N个整数的序列(顺序固定),通过加或减的运算,结果能否被K整除 思路 用二维bool数组存余数情况 dp[N][K] 变量i :考察到第 i个数 变量j :第 j个余数的情况 dp[ i ][ j ]:前 i个数是否能运算出余数 j AC代码 #include <bits/stdc++.h> using namespace std;...

LiO_Liu的博客 248

Tube-based MPC完全指南:RCI集合构造与Matlab实现

模型预测控制(MPC)在实际工程中常因模型失配和外部扰动导致硬约束被突破,而鲁棒控制中的Tube-based MPC通过将单条预测轨迹扩展为“管道”集合,为不确定性提供了严格的安全边界。其核心在于利用鲁棒控制不变集(RCI)离线构造安全域,再结合在线标称MPC与反馈校正实现约束的硬保证。针对非线性系统,利普希茨条件为等效扰动的放大和RCI的构造提供了理论基础,使得算法既能保留非线性描述,又不牺牲在线计算效率。该方法适用于带扰动和参数漂移的机械系统、过程控制及嵌入式控制场景。本文以摩擦力非线性系统为例,从RC

weixin_32642109的博客 215

TSMaster如何用珠海创芯CAN卡实现高效CAN通信(附完整驱动安装指南)

本文详细介绍了如何使用TSMaster软件与珠海创芯CAN卡实现高效CAN通信,包括驱动安装、系统配置、ControlCAN.dll替换及TSMaster集成配置等关键步骤。通过实战指南和故障排除技巧,帮助工程师快速搭建稳定可靠的CAN通信测试环境,适用于汽车电子和工业控制等领域。

weixin_29201859的博客 479

poj 1745 Divisibility

题目链接: http://poj.org/problem?id=1745 题意: 给出N个数a[i],在中间填上加号或减号,问能否出现一种填法使和能被K整除 题解: 我们可以 bool dp[i][j] = true 表示前i个数的和可能出现j,再通过dp[i][j] = true 当dp[i-1][j-a[i]] = true 或 dp[i-1][j+a[i]]

t51645的博客 316

【3天快速入门WPF】1-从最简单的xaml开始

首先我们要知道xaml语法中声明即定义,意思就是“见到元素就相当于创建实例”,MainWindow.xaml的主干是一个元素里包含着一个 元素。这段程序就是在定义一个Window类的实例,这个实例的一个组成部分是一个Grid类的实例。

Zy100Papa的博客 1623

POJ1745Divisibility【dp】

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

走一步再走一步 733

YOLOv8全网首发:CVPR2026 MixerCSeg | DEGConv方向引导边缘门控,破解细长裂缝检测难题

DEGConv通过方向先验嵌入、边缘增强卷积和动态门控三大机制,针对性解决了YOLO在处理裂缝类细长、多方向、低对比度目标时的特征提取不足问题,显著提升了裂缝检测的精度与鲁棒性。

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 516

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

POJ1745-Divisibility

http://poj.org/problem?id=1745 #include<stdio.h> #include<string.h> int a[10001],n,m; bool dp[10001][101]; int main(void) { int i,j,t1,t2; scanf("%d%d",&n,&m); ...

weixin_30241919的博客 102

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

【DP】POJ-1745 Divisibility

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

JSure的代码库 1169

android 蓝牙通讯demo

android 下蓝牙通讯demo,实现了发现蓝牙,使能蓝牙,通过蓝牙发送消息。

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

POJ 1745 Divisibility

链接:http://poj.org/problem?id=1745 题意:给定N个数,问进行加减运算之后的结果是否能被K整除。   分析:DP。设布尔型数组dp[][],dp[i][j]表示对前i个数进行加减运算的结果模K的值为j。共N个阶段,每个阶段K个状态。 状态转移方程为:if(dp[i-1][j])      dp[i][abs(j+num[i])%k]=true;

iCpC之旅 893

poj 1745 Divisibility(DP + 数学)

poj 1745 Divisibility(DP + 数学)

1986

POJ-1745 Divisibility 【数塔模型】

J - DivisibilityTime Limit:1000MS Memory Limit:10000KB 64bit IO Format:%lld & %llu SubmitStatus Description Consider an arbitrary sequence of integers. One can place + or - operators between

DTL66的博客 446

POJ 1745 Divisibility

Divisibility Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%lld & %llu Submit Status Description Consider an arbitrary sequence of integers. One can place + or - opera

※夏日星空※ 327

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

poj 1745-Divisibility

http://poj.org/problem?id=1745 此题暴力明显没有前途,2的10000次方,此题也是DP,关键是要用到一个公式(a+b)%p=(a%p+b%p)%p,以及(a-b)%p=(a%p-b%p+p)%p,这里注意,要是括号的里是负数就不成立了,所以后面一个等式加了p。在读入数据的时候就可以先%p,再把是负数的加上p。每一次加一个数字就要%p,减一个就要加p再%p,跟18

glq007的acm的奋斗 1172

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的博客 138

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

POJ1745 Divisibility(dp)

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

GKHack's Blog 1121
上一篇: POJ3186Treats for the Cows题解动态规划DP
下一篇: POJ1651Multiplication Puzzle题解动态规划DP
power721
博客等级 码龄18年 176粉丝 135原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值