二个分数的组合的运算的问题,怎么采用C语言程序的编写的方式实现?

Problem Description
As the chief consultant in the International Consulting Company, you’re now enjoying such a high reputation in the industry that even the organizations underworld often come to you and ask for your suggestions. Professional as you are to your clients, you always try your best to help them and, certainly, make more profits for yourself. Money makes the mare go, and you’re no exception either.

But the shareholders of the company are always watching their profits as well. In order to protect the investors, they keep focusing on every project you take charge of. Once you receive money in a project, they will come immediately to you. If your profit is less than M dollars, they won’t step in; but if the profit reaches M , they will meddle in and take away profits in unit of M as much as possible. (e.g. if you earn (2M + 1) or exactly 2M dollars, they will both take 2M away.)

Now a big client comes. A famous robbery organization expects you to help them construct a robbery plan. The offer is so irresistible that you accept it immediately.

Their targets are the banks in the city. Totally, there’re K banks (numbered from 1 to K) that located at different areas, which produce different difficulties to rob them. The robbery team is made up of N people, and they have totally Q dollars as action funds. In a robbery, if they send p people and spend d dollars of funds to rob bank i, they will earn fi[p, d] in this action. Here, fi[p, d] is generated by
fi[p, d] =0 (p <= 0 or d <= 0)
fi[p, d] = fi[p - 1, d - ei] + fip - 1, d
and fi[1, d] comes from
fi[1, d] = Aif2i[1, d - 1] + Bifi[1, d - 1] + Ci (1 <= d <= Q)
where ei, Ai, Bi, Ci are coefficients given initially.

The team is so professional (as you are) that the members always succeed in robberies. After they rob a bank and get the money, the team will divide it into (almost) equal parts and distribute them to you and everyone who participates in this action. That is, if they send p men and rob X dollars, you’ll receive dollars immediately after the robbery on this bank. But at the time you receive the money, the damned shareholders will come and take away the part of theirs. Only the remaining part belongs to you.

You’re now required to help them determine the plan. Note that the robberies won’t take place simultaneously; and thus each person can rob several banks, but each bank can be robbed at most once (if we choose to rob it). The money they rob won’t be added to their action funds afterwards. Your final profit equals to the sum of profits that belongs to you after each robbery (Note that your total profit will not be checked again by the shareholders, i.e. your total profit may exceed M ).

Your target, professionally speaking, is to maximize the total profit of yourself after they finish robbing the banks according to your plan. Be careful of the annoying shareholders in the company!

Input
The input consists of several test cases. The first line of input gives the number of test cases T (T<=5).

For each test case:
The first line consists of four integers N, Q, K(1<=N<=1000, 1<=Q<=20, 1<=K<=50) and M (1<=M<=106).
The following K lines describe the property of banks, where the ith line contains ei, Ai, Bi, Ci(1<=ei<=Q, 1<=Ai, Bi, Ci<=109) in order.

Output
For each test case, output the maximum profits you can obtain in a line.

Sample Input
1
80 10 1 1000000
1 988123 894129 102939

Sample Output
999996

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
C语言程序 分数加减法
C语言程序 1-(1/2)+(1/3)-(1/4)+……-(1/100);
多项式运算的C语言程序
多项式运算,两个多项式相加和相乘运算的相关C语言程序
c语言程序编写的五子棋
c语言编写的两人对弈五子棋,双方各执一种颜色的棋子,交替下子,不能连续下两次,当一方五颗棋子连在一起为获胜!
C语言程序编写!
有一个C语言程序的要求是这样的:rn 对于一个自然数n(n<=50),统计具有下列性质的数的个数:自然数n,在n的左边加上一个自然数,但该rn自然数不能超过原数的一半;继续按此规则进行处理,直到不能再加自然数为止,例如6,16,26,126,36,136,rn一共6个。rn 程序如下:rnint s=0;rnvoid left(int n)rn int n1;rn if(n>0)rn s++;rn for(n1=1;n1<=n/2;n1++)rn left(n1);rn rn rnvoid main()rn int n;rn clrscr();rn printf("input an integet:\n");rn scanf("%d",&n);rn left(n);rn printf("s=%d\n",s);rnrnrn上面的程序仅统计了符合条件的数的个数。如何改进程序,输出所有的数??rnrnrn
编写安全的C语言程序
对外部输入进行校验 不要硬编码敏感信息 避免对有符号数进行位运算 对指定内存申请长度的整数值进行校验 禁止使用realloc 禁止使用alloca 禁止使用OS命令解析器system()或popen()等,应该使用exec()、CreateProcess()等。
凌阳C语言程序编写
凌阳C语言程序编写
编写大规模的C语言程序
为了支持大规模C程序的开发,往往需要把程序分割为一定数量的源文件。C语言的源文件包括两类,一类是实现文件(.c),一类是头文件(.h)。一般地,实现文件主要包括函数和变量的定义,而头文件的作用是在多个定义文件中共享函数原型、宏定义和类型定义、变量声明等信息。
VC6。0怎么编写C语言程序
我是个初学的菜鸟,开始是用TURBOC2来写的,VC6.0就不知道怎么建编辑窗口.可以建立的类型找不到.rn谁能告诉我具体选哪个可以编辑C语言啊.具体的类型名字.谢谢.
二个问题,分数送完!
1、在STRUCTS 中,是不是每一个JSP页面都以*.do方式访问?rn2、如果是,那岂不是在配置文件中配置大量的映射信息?rn
C运算符的运算顺序和组合
首先先感谢大家可以来看这个帖子。rnrn标题说的可能不是很清楚,具体来说如图的这两个程序;分别是(用的codepad在线编译输出的)rn[color=#FF0000]图1[/color]rn[img=https://img-bbs.csdn.net/upload/201305/06/1367845692_236249.png][/img]rnrnrn和[color=#FF0000]图2[/color]rn[img=https://img-bbs.csdn.net/upload/201305/06/1367845712_192554.png][/img]rnrn第一张图里面,整个运算表达式的值我可以理解,但是对a的操作就没理解,为什么变量a在这些运算后会变成这些值呢?rnrn第二张图里,第一行输出很容易理解;后三行的我都无法理解为什么经过这样的运算以后,操作数会变成这些值?rnrn感谢大家帮忙解释。谢谢~~~
分数的运算,运算符重载问题
分数的运算,运算符重载问题rn自己看了好久还是发现不了错误,谢谢指点。第一部分是头文件rn// 8.16 rationalNumber.hrnrn#ifndef RATIONALNUMBER_Hrn#define RATIONALNUMBER_Hrnrn#include rnrnusing namespace std;rnrnclass RationalNumberrnfriend ostream &operator<<(ostream &, RationalNumber &);rn//friend RationalNumber &operator+(const RationalNumber &,const RationalNumber &);rn//friend RationalNumber &operator-(const RationalNumber &,const RationalNumber &);rn//friend RationalNumber &operator*(const RationalNumber &,const RationalNumber &);rn//friend RationalNumber &operator/(const RationalNumber &,const RationalNumber &);rnrnpublic:rn RationalNumber(int=1,int=1);rn RationalNumber(const RationalNumber &);rn ~RationalNumber();rn void simplify();rn const RationalNumber &operator+=(const RationalNumber &);rn const RationalNumber &operator-=(const RationalNumber &);rn const RationalNumber &operator*=(const RationalNumber &);rn const RationalNumber &operator/=(const RationalNumber &);rn const RationalNumber &operator=(const RationalNumber &);rn bool operator==(const RationalNumber &) const;rn bool operator!=(const RationalNumber &right) constrn rn return !(*this==right);rn rn bool operator<(const RationalNumber &) const;rnrn bool operator>=(const RationalNumber &right) constrn rn return !(*this(const RationalNumber &) constrn rn return right<*this;rn rn bool operator<=(const RationalNumber &right) constrn rn return !(right<*this);rn rn rnprivate:rn int numerator;rn int denominator;rn char *fptr;rn;rn#endifrnrn第二部分,函数定义rn//8.16 rationalNumber.cpprn#include rn#include rn#include rn#include rnrnusing namespace std;rnrn#include "rationalNumber.h"rnrnRationalNumber::RationalNumber(int a, int b)rn rn numerator=a;rn denominator=b;rn simplify();rn rnRationalNumber::RationalNumber(const RationalNumber ©)rn rn numerator=copy.numerator;rn denominator=copy.denominator;rn rnRationalNumber::~RationalNumber()rn rn delete fptr;rn rnrnvoid RationalNumber::simplify()rn rn if(denominator==0)rn rn cout<<"Error!!! Denominator cannot be zero!!"<rn#include rn#include rn#include rnrnusing namespace std;rnrn#include "rationalNumber.h"rnrnint main()rnrn RationalNumber f1(3,8);rn RationalNumber f2();rn RationalNumber f3(10,16);rn rn cout<<"f1= "<="<
分数的运算
原题题址 题目描述 我想听话啊,但人家就是控制不住自己嘛! ——百里玄策-白虎志 小T是一个非常无聊的人,他写了两个分数x1y1 x2y2 ,他现在让小s求他们的和差积商。 小s哪里会这样的题目,于是他请教于你。 注意:如果出现负数则一律将符号放在分子上,即除分子外,答案中的其他数必须是非负数。 输入描述: 一行x1,y1,x2,y2 输出描述: 四行,每行两个整数x,y代表答案为x...
分数运算
1. 分数加减乘除。 2. 注意精度。 3. 注意求最大公约数时的大小关系。
MSP430的C语言程序编写规范
MSP430的C语言程序编写规范,对新学MSP430 C编程的人可能会有些帮助。
使用VS2010编写C语言程序
本文档讲述了如何在VS环境下编写语言程序!本文档经过测试绝对可用!
C++ 实现的分数运算的重载
编程语言:C++ 编译环境:VS2008 实现功能:分数运算的重载 参考方向:C++ 操作符重载 适用于初学者参考
c语言程序c语言程序
本资源对《湖南省高等学校计算机水平等级考试复习指导》中的110个程序设计题进行了解答,纠正了书中答案的错误部分,对准备湖南省计算机等级考试的同学有帮助。
C语言程序编写规范,简化版
C语言程序编写规范,比较简单,仅供参考。来源于网络,如有不足,欢迎评价中提出意见。
关于x-code编写c语言程序
问大家一个问题,我写一个关于文件复制的程序,用getchar()的,但是用x-code似乎跑不了,不知道大家遇到这个问题没有。
Linux下编写运行C语言程序
1.进入目标文件夹,打开终端,输入 touch test.c 创建文件 2.然后输入 vim test.c来编辑文件。 3.编写完后,输入 gcc test.c 编译c文件, 生成 a.out文件。如果想自定义out文件名字, 可以用:gcc test.c -o test.out 4.终端输入 ./test.out 就可以运行了 ...
2、编写第一个C语言程序
编写第一个C语言程序 新建空文件,命名为HelloWorld.c 用geany打开文件,编写C程序,并保存 用gcc指令进行编译 执行编译后的文件 具体代码如下: #include &lt;stido.h&gt; int main() { printf("HelloWorld.c \n"); } 编译,指定编译后的文件为HelloWorld: 在-o后指定 gcc HelloWo...
PWM调速的C语言程序编写
PWM调速的C语言程序编写PWM调速的C语PWM调速的C语言程序编写言程序编写
编写最简单C语言程序
#include<stdio.h> void main() { printf("This is a sample of c program.\n"); }
编写无误的c语言程序秘诀
如果你想更好地提高你写程序的效率,这本书值得你仔细地看看,因为其中包含了前辈们对计算机语言编写的经验总结,值得一看。
用C语言程序编写的万年历
实现了万年历的许多功能,可以查询日历,可以调用系统当前日期状态
编写c语言程序遇到一些问题
1.读取文件路径时,是双斜杠,如果是单斜杠,会出现找不到目标文件的情况 fid = fopen(&quot;E:\\my_c\\cloud_detection\\cloud_detection\\cloud\\gray_13.txt&quot;, &quot;rb&quot;); 2.数组使用前要进行内存分配和初始化,一定要初始化,不然有可能出现读取位置XXX时发生访问冲突的问题 labelmap = (int *)mall...
用C++编写的分数加减乘除的运算
#include <iostream> using namespace std; class fen { public: //fen(){a=0;b=0;} fen(int x=1,int y=1){a=x;b=y;} ~fen(){} void show(){cout<<a<<"/"<<b<<endl;} fen operator+(fen &f1); fen operator=(fen &f1); private: int a,b; }; fen fen::operator +(fen &f1) { int x,y,g(1); x=a*f1.b+b*f1.a; y=b*f1.b; for(int j=2;j<x;j++) if(x%j==0&&y%j==0&&j<y) g=(g>j?g:j); a=x/g; b=y/g; return *this; } fen fen::operator =(fen &f1) { a=f1.a; b=f1.b; return *this; } int main() { fen f1(1,4),f2(3,5),f3=f1+f2; f3.show(); return 0; }
Css编写尽量采用组合样式
未采用组合样式:   采用组合样式:(推荐采用以下方式编辑Css)   且推荐写在一行的写法:
c语言程序 ———栈的实现
#includen#includen#define STACK_INIT_SIZE 10n#define STACKINCREMENT 2nstruct Stacknn char *base;n char *top;n int stacksize;n;nstruct Stack *InitStack(struct Stack *S) //创建空栈nn S->base=(char *)malloc(STACK_INIT_SIZE * sizeof(char));n if(!S->base) printf("error!"); return 0;n S->top=S->base;n S->stacksize=STACK_INIT_SIZE ;n return S;nnstruct Stack *Push(struct Stack *S,char e) //向栈中插入元素nn if(S->top-S->base==S->stacksize)n n S->base=(char *)realloc(S->base,(S->stacksize+STACKINCREMENT * sizeof(char)));n if(!S->base) printf("分配空间失败"); return 0;n S->top=S->base+S->stacksize;n S->stacksize+=STACKINCREMENT;n n *(S->top)=e;n S->top++;n return S;nnvoid Pop(struct Stack *S,char e) //删除栈顶元素,并且返回其值nn if(S->top==S->base) printf("栈为空,无法删除栈顶元素"); return 0;n e=*(--S->top);n printf("删除的栈顶元素为:");n printf("%c\n",e);nnint main()nn struct Stack *S;n int e;n char i;n S=(struct Stack *)malloc(STACK_INIT_SIZE * sizeof(char));n if( !S->base) printf("error!");n InitStack(S);n printf("输入要插入的元素e:");n scanf("%c",&e);n Push(S,&e);n Pop(S,&i);n return 0;n nnn以上是我写的c语言程序,运行的时候不管输入什么,输出的都是x,求哪位大神讲解下为什么,实在是百思不得其解
用函数怎么顺序组合二个字符串
就如"rnA="第一节$Array$第二节$Array$第三节$Array$第四节"rnB="天杀$Array$一人$Array$天地人$Array$无风"rnrn怎么把上面的二个字符串,组合成以下rnrn第一节$天杀rn第二节$一人rn第三节$天地人rn第四节$无风rnrn我是菜鸟,请问大家这个怎么组合啊.谢谢....就用函数哦.不要正则表达式哦,谢谢
C语言程序:日历的实现
部分代码: int main(int argc, char *argv[]) { int year,month,leap_year,i,j,days_this_year,week_days; long days; int months[12]={31,28,31,30,31,30,31,31,30,31,30,31}; leap_year=0; days_this_year=0; days=0; week_days=0; printf("Please input year and month:"); scanf("%d,%d",&year,&month); for(i=1900;i<year;i++) { if((i%4==0&&i%100!=0)||(i%400==0)) { leap_year++; } } if((year%4==0&&year%100!=0)||(year%400==0)) { months[1]=29; } for(i=0;i<month-1;i++) { days_this_year+=months[i]; } //days_this_year+=day; days=(year-1900)*365+leap_year+days_this_year; week_days=days%7+1; printf("日 一 二 三 四 五 六\n"); for(i=0;i<week_days;i++) printf(" "); for(i=1;i<=months[month-1];i++) { printf("%-4d",i); week_days++; if(week_days%7==0) { week_days=0; printf("\n"); } } printf("\n"); // printf("%ld\n",days); return 0; }
实现开关操作的C语言程序
”~“可以实现取反的操作,再加上if else 选择操作来判断。static u8 switch_key0 = 0;switch_key0 = ~switch_key0; if(switch_key0) {            Moto_X_switch_On;            printf(&quot;1开\n&quot;); }  else  {            Moto_X_switch_OFF;...
怎么采用C语言的程序编写的过程实现序列的删除
Problem Description There is an undirected graph G with n vertices and m edges. Every time, you can select several edges and delete them. The edges selected must meet the following condition: let G′ be graph induced from these edges, then every connected component of G′ has at most one cycle. What is the minimum number of deletion needed in order to delete all the edges. Input There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case: The first line contains two integers n and m (1≤n≤2000,0≤m≤2000) -- the number of vertices and the number of edges. For the next m lines, each line contains two integers ui and vi, which means there is an undirected edge between ui and vi (1≤ui,vi≤n,ui≠vi). The sum of values of n in all test cases doesn't exceed 2⋅104. The sum of values of m in all test cases doesn't exceed 2⋅104. Output For each test case, output the minimum number of deletion needed.
急需有限域的乘法运算C语言程序
GF(2的16次方)上的乘法运算,需C语言程序。请各位老师帮忙解答。
如何提升C语言程序的运算精度?
用C语言进行算数运算的时候如何提升C语言的运算精度问题?使用FLOAT来定义变量吗?rn
c语言程序编写 c语言循环结构的嵌套
#include<stdio.h> main() {int k,i,j; for(i=o;i<3;i++) {for(k=0;k<3-2;k++) printf(""); for(j=0;j<2i+1;j++) printf("*"); printf("\n"); } for(i=0;i<4;i++) {for(k=1;k<=i;k++) printf(""); for(j=0;j<7-i*2;j++) printf("*"); printf("\n"); } }
C语言学习之编写第一个C语言程序
如果用C语言输出:Hello,world!,该如何编写程序? **代码如下:** #include&amp;amp;lt;studio.h&amp;amp;gt; //包含标准库的信息 main() //定义名为main的函数,不接受参数值 { //main函数...
POJ-3979-分数加减法(分数运算)
//传送门:http://poj.org/problem?id=3979 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespa
关于C的二个问题
最近看一个程序,发现有二个小地方不明白rn第一个是 rnNALU *Generate(int PPS_id)……rnNALU是头文件中定义的一个结构体,我不明白结构体定义一个函数是什么意思rn还有下面这个与上面的这个定义方式有什么不同,TextureContexts也是定义的结构体rnTextureContexts* create_Text(void)……rnrn第二个是rnint IdentifyLevel(void)rnrn return input->LevelIDC;rn;rn为什么函数结束的大括号后要一个分号rn谢谢
数据结构采用C语言编写
采用C语言编写,里面有查找(分块,顺序,折半,哈希查找),排序(插入排序:直接插入排序、折半插入排序、希尔排序;交换排序:冒泡排序、快速排序;选择排序:简单选择排序、堆排序;归并排序:2-路归并排序;基数排序),树和二叉树,图和表,队列和栈,这些代码演示.....
相关热词 c# 去空格去转义符 c#用户登录窗体代码 c# 流 c# linux 可视化 c# mvc 返回图片 c# 像素空间 c# 日期 最后一天 c#字典序排序 c# 截屏取色 c#中的哪些属于托管机制

相似问题

2
一个数字取模运算的问题,用C语言怎么实现的呢?
1
C语言四则运算计算器的一个问题
1
如何使用C语言实现逆波兰运算(加减乘除)求值?
1
c语言中在运算中如何实现指数运算?
1
这个问题除了循环运算以外,怎么才能优化C语言的算法实现?
0
大整数的连续运算步骤的问题,采用C语言,计算每个序列都要输出
0
下面这个人数的统计的运算的方式,采用C程序设计怎么解决呢?
0
一个大数的四则运算的问题,求出指数的运算结果,采用C语言程序的解决
1
英文字母的消息编码问题,采用C语言实现对字母字符串的解码运算
0
在此题中,气球的颜色的值通过运算获得的方式?采用C语言实现
0
列竖式计算的一个代换问题的算法难题,采用C语言如何运算的
0
关于算术运算符和位运算符的一个问题,采用C语言程序的技术来编写程序
0
用竖式计算的一个二进制运算的问题,怎么才能利用C语言的方式的程序来设计
0
根据算法的过程实现密码的解码运算的技术,怎么采用C程序的设计的语言实现
0
最大角度的一个运算的解决,怎么利用C语言的程序的设计的技术来实现的
0
C语言程序设计一个小学生四则运算系统
0
一个天气遇到的计算的运算的算法,怎么利用C语言的程序的设计的方式实现的
1
用c语言,实现多个数的四则运算,求大神帮帮忙。
1
C语言:逻辑运算符的使用
0
函数递归运算的运用算法问题,怎么采用C语言的程序的设计的思想实现?