Writing Code(DP)

【TestCenter】RFC2544时延测试 本文介绍了使用Spirent TestCenter测试路由器PPPOE时延的RFC2544标准方法。RFC2544定义了三种时延类型:转发时延(LILO)、存储转发时延(LIFO)和直通时延(FIFO)。文章详细说明了测试步骤,包括测试拓扑搭建、PPPOE环境配置、RFC2544测试任务创建等关键环节,并介绍了如何设置时延参数和查看测试报告。测试结果表明,大字节帧的时延高于小字节帧,且负载越高时延越大。该测试方法遵循国际标准,可全面评估网络设备在不同负载下的性能表现。 阅读详情

Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers working on a project, the i-th of them makes exactly ai bugs in every line of code that he writes.

Let’s call a sequence of non-negative integers v1, v2, …, vn a plan, if v1 + v2 + … + vn = m. The programmers follow the plan like that: in the beginning the first programmer writes the first v1 lines of the given task, then the second programmer writes v2 more lines of the given task, and so on. In the end, the last programmer writes the remaining lines of the code. Let’s call a plan good, if all the written lines of the task contain at most b bugs in total.

Your task is to determine how many distinct good plans are there. As the number of plans can be large, print the remainder of this number modulo given positive integer mod.

Input
The first line contains four integers n, m, b, mod (1 ≤ n, m ≤ 500, 0 ≤ b ≤ 500; 1 ≤ mod ≤ 109 + 7) — the number of programmers, the number of lines of code in the task, the maximum total number of bugs respectively and the modulo you should use when printing the answer.

The next line contains n space-separated integers a1, a2, …, an (0 ≤ ai ≤ 500) — the number of bugs per line for each programmer.

Output
Print a single integer — the answer to the problem modulo mod.

Sample test(s)
input
3 3 3 100
1 1 1
output
10
input
3 6 5 1000000007
1 2 3
output
0
input
3 5 6 11
1 2 1
output
0

n个人,m行代码,最多有b个错误,每个人写一行有a[i]个bug,问满足的分配方案的个数。

写了三遍总算是会了(……),dp[i][j][k],前i个人,写了j行,小于等于k个bug的方案数。
然后转移方程就是
dp[i][j][k] = dp[i - 1][j][k] + dp[i][j - 1][k - a[i]];
意思就是这个状态是由第i个人不写第j行和写第j行转移过来。
此时发现第一维可以省略掉(不开这个空间)

#include<cstdio>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1005;
int dp[505][505];
int a[505];
int main()
{
    #ifdef LOCAL
    freopen("C:\\Users\\巍巍\\Desktop\\in.txt","r",stdin);
    //freopen("C:\\Users\\巍巍\\Desktop\\out.txt","w",stdout);
    #endif // LOCAL
    int n,m,b,mod;
    scanf("%d%d%d%d",&n,&m,&b,&mod);
    for(int i = 1;i <= n;i++)
        scanf("%d",&a[i]);
    memset(dp,0,sizeof(dp));
    for(int i = 0;i <= b;i++)
        dp[0][i] = 1;
    for(int i = 1;i <= n;i++)
    {
        for(int j = 1;j <= m;j++)
        {
            for(int k = 0;k <= b;k++)
            {
                if(k < a[i])dp[j][k] = dp[j][k];
                else
                    dp[j][k] = (dp[j][k] + dp[j - 1][k - a[i]])%mod;
            }
        }
    }
    printf("%d\n",dp[m][b]);
    return 0;
}
Spring AI 项目实战(五):Spring Boot + AI + DeepSeek + Redis 实现聊天应用上下文记忆功能(附完整源码) 本文介绍了如何基于Spring Boot 3.2、Spring AI 1.0.0-M4、DeepSeek API和Redis构建具备上下文记忆功能的智能聊天应用。项目采用现代化技术栈,包括Java 17、Maven、Lombok等,实现了智能对话、会话管理、异常处理等核心功能。文章详细讲解了环境搭建、配置管理(含Redis和AI服务集成)、核心组件设计(如消息实体、控制器和服务层实现),以及完整的项目结构。该项目提供了美观的Web界面和REST API,支持对话上下文存储(通过Redis实现)和系统监控,可 阅读详情

相关推荐

零售-公司间关联交易退货STO的实现方式

零售-公司间关联交易采购 STO-退货 集团公司下经常会出现一家公司和另外一家公司的公司间的关联交易,如跨公司销售、总分公司之间采购,分公司之间的采购等业务;通常公司间采购会采取STO的模式来实现(根据业务模式可以将库存转储统一做成STO的模式,公司间STO、同公司工厂间、同工厂库存地点间 的STO SAP都是支持的); 公司间STO 正向A向B采购都很熟悉,公司间退货STO的其实也是比较普遍的业务现象,很多实施着也将其做成反向的STO(B向A采购),而不是退货STO(A向B,item 选择return的标

weixin_45518759的博客 2835

Writing Code(详细)

思路 代码 #include <iostream> #include <algorithm> using namespace std; const int N=1010; int n,m,b,mod; long long sum; long long f[N][N],a[N]; int i,j,k; int main() { cin>>n>...

萌新的博客 603

[Codeforces 543A] Writing Code (完全背包DP)

Codeforces - 543A NN 个人写共计 MM 行代码,第 ii 个人每写一行代码就有 aia_i 个bug 问使得 MM 行代码都被写完,并且总 bug不超过 BB 的方案数 背包DP…… 太久没写了已经不会写了…… dp[n][m][b]表示当前为第 n个人,还剩 m行代码,b个可容许bug 然后无须枚举当前人写了几行代码,只需要从大到小枚举 m 然后把状态还是更新第

MisDeer's blog 388

python解析通达信dat与blk数据文件【附源码】

本文介绍了一个完整的通达信金融数据解析器项目,该项目攻克了通达信专有二进制文件格式解析的技术难题。项目采用模块化架构,从基础二进制解析到增强数据分类,最终实现智能语义化列名生成,形成完整的数据处理链路。核心技术包括自适应编码检测、智能数据类型推断和基于业务规则的语义化处理,解决了逆向工程、多编码兼容性等挑战。项目成果显著,解析成功率达100%,数据可读性大幅提升,开发效率提高50%,为量化交易、可视化分析等场景提供了可靠数据支持。该方案不仅具备技术创新性,更具有实际工程应用价值,为金融数据分析领域提供了可复

qq_36224726的博客 2689

巨量千川M-API实战:异步报表与批量操作自动化指南

API(应用程序编程接口)是现代软件系统间通信和数据交换的核心技术,它定义了服务间交互的协议和规范。在数字营销领域,营销API(Marketing API)通过程序化接口实现了广告账户管理、数据获取和操作自动化的能力,其技术价值在于将重复性人工操作转化为高效、准确的自动化流程,显著提升运营效率并降低人为错误。在广告投放精细化运营场景中,面对海量数据报表的获取与批量广告状态管理的需求,异步任务处理和批量操作接口成为关键技术解决方案。本文聚焦巨量千川M-API,深入解析其异步报表获取机制与批量操作实现,涵盖从任

weixin_32932149的博客 429

Writing Code(dp)

A. Writing Code time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Programmers working on a large project have just re...

weixin_34416754的博客 191

多孔材料吸附性质模拟程序RASPA的离线和在线安装方法

RASPA-2.0是今年美国西北大学教授Randall Q. Snurr等人开发的针对于MC,MD,分子力学优化等用途的程序,相比于之前开发的MUSIC软件,RASPA的功能更加齐全,操作更加简便,可以在MC的吸附过程中考虑骨架的柔性,也可以想MUSIC一样先制作积分格点(music中的map)。 A、离线安装(centos为例): (1)、安装之前要检查一下是否装了automake,

youyno的博客 1万+

[CodeForces 543A]Writing Code[DP]

题目链接:[CodeForces 543A]Writing Code[DP] 题意分析: n个程序员合作写m行代码,第i个程序员每次写一行会产生a[i]个bug,程序员顺序工作,1工作之后2工作,如此类推,现在要求总bug数不得超过b。问:写完m行代码,总bug数不超过b的方案有多少种? 解题思路: 首先我们试着定义一个状态,由于程序员顺序工作,那么我们定义dp[i][j]为写了i行代码,

闲停 712

CAPL诊断功能实现

UDS(Unified Diagnostic Services)是一种用于汽车电子系统诊断的标准协议。它定义了一系列诊断服务,用于读取和写入车辆电子控制单元(ECU)中的数据,以及处理诊断故障码(DTC)。UDS协议通常运行在CAN总线上,使用ISO 15765-2(ISO-TP)协议进行数据传输。通过本文的学习,读者应该对CAPL诊断功能实现有了初步的了解,并能够编写复杂的CAPL脚本。在实际项目中,CAPL的应用非常广泛,希望读者能够通过不断的学习和实践,掌握更多的CAPL技巧,提高自己的开发能力。

闲人编程的博客 1517

DBT关键切片重建算法

DBT通过有限角度(通常15°~50°)扫描,获取一系列低剂量投影图,重建出三维断层图像。传统FBP在稀疏角度下会产生严重的“伪影拖尾”和层间干扰。临床诊断中,放射科医生往往只关注几层关键切片(即病灶所在层),其余层仅作参考。

AI的内部世界的博客 89

Codeforces Round #302 (Div. 2)C (完全背包)

C. Writing Code time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Programmers working on a large project have

u013268685的专栏(有一种幸福叫AC,有一种期待叫AK) 1186

Autosar入门_OS_5

os hook函数说明

u012406840的博客 399

DP与朴素算法差异 【CF】Writing Code

Writing Code time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Programmers working on a large project have just received a task to ...

SummerDream 251

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

jre9下载 jdk9

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

Codeforces 543A. Writing Code DP

A. Writing Code time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Programmers working on a large project have

码代码的猿猿 1289

VB摄像头监控

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

Writing Code - CodeForces 543 A dp

Writing Code time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Programmers working on a large project have ju

提比的强行AC 721

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

CodeForces 543A - Writing Code DP 完全背包

有n个程序,这n个程序运作产生m行代码,但是每个程序产生的BUG总和不能超过b, 给出每个程序产生的代码,每行会产生ai个BUG,问在总BUG不超过b的情况下, 我们有几种选择方法思路:看懂了题意之后就是一个完全背包题了 定义dp[ i ][ j ][ k ] 表示前 i 个程序员,已经写了 j 行代码, 已经产生了 k 个 bugs 。 根据题意,得知第 i 个程序员会写 r 行代码,...

weixin_30748995的博客 190

Codeforces 543A Writing Code 【滚动数组优化dp】

A. Writing Code time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Programmers working on a large project have

世界很大 596

codeforces 543A Writing Code (dp)

一开始想到的dp: f [ i ][ j ][ k ]表示前i个人打了j行有k个错误的方案数,那么转移方程为:f [ i ][ j ][ k ]=f [ i-1][ j-h ][ k-a[i]*h ] (0 很明显超时+MLE。 这时会发现转移只与f [ i-1 ]有关,可以通过降一维来优化,删去第一维。 f [ j ][ k ]=f [ j ][ k ]+f [ j-1 ][ k-a[i]

KatnissJ的博客 816

Codeforces 543 A Writing Code 计数DP

http://codeforces.com/problemset/problem/543/A 题目大意:n个人,一共要写m行程序,每个程序员每行出现的bug数为ai,要求整个程序出现的bug数不超过b的方案数. 题目分析:简单的计数DP,01背包变形。需要记录的是写到第i行时错误的bug数为j的方案。所以定义二维数组dp[i][j]。转移与01背包类似。具体见代码;初始化d

WKLL_ 1015

codefroces 543A Writing Code dp优化 完全背包

Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers working on a project, the i-th of them makes exactly ai bugs in every line of

黑码 556

CodeForces 543A Writing Code(dp)

题意:告诉你每个程序员写一行代码会产生多少bug,问你n个程序员写m行代码 bug数不超过b的分派方案有多少个。 一开始想到的状态就是dp[i][j][k]表示前i个程序员写了j行代码,bug 不超过k的方案,发现转移是三方的,其实这个状态时刻一改变一下的, 因为最后的程序员可以写,也可以不写,不管写了几行,所以状态转移就只 需要看最后的那个程序员是否写了就行,另外可以滚动数组。 dp[i][j][

只玩三国的程序猿的专栏 536

cf#302 C. Writing Code dp

点击打开链接 题意:有n个程序员,第i个程序员每行会有ai个bug,然后让你按着顺序安排程序员,问你有多少种安排方法,可以使得写m行的bug最多b个 思路: dp[i][j]表示写i行bug数有j个的方法数 转移方程和背包问题类似  最后扫一遍统计一下就好 代码: #include using namespace std; const int maxn =

yxg_123的博客 249

CodeForces 543A Writing Code(DP)

题目链接:http://codeforces.com/problemset/problem/543/A 题意:安排n个人写m行代码,每人每行会出现a[i]个bug,问最多出现k个bug的方案数 思路:令dp(i, j, k)表示前i个人写j行代码未超过k个的方案数,然后就可以类似背包进行转移并降掉一维的空间复杂度 #include <cstdio> #i...

Tongqi 644

Codeforces Round #302 (Div. 1) 543A Writing Code(dp)

A. Writing Code time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Programmers working on a large project have

GKHack's Blog 1072

背包DP || Codeforces 544C Writing Code

程序员写bug的故事23333 题意:n个程序员,一共写m行程序,最多产生b个bug,问方案数 思路:f[i][j]表示写了i行,产生了j个bug的方案数,因为每个人都是可以独立的,所以i循环到n都做一遍 f[i][j] += f[i-1][j-a[i]] 在前一行 i 的 a[i] 个bug还没有写上去的情况数 #include <iostream> #include ...

weixin_30390075的博客 107
上一篇: cf599D Spongebob and Squares(推公式,枚举)
下一篇: Maximum Absurdity(dp)
Techay
博客等级 码龄11年 11粉丝 174原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值