| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 14791 | Combination Sum Problem |
|
| 14794 | Evaluate function and find maximum value |
|
Description
This program calculates the total number of ways to select at most m different items from n distinct items. To accomplish this, define a function that computes the binomial coefficient C(n,m), which represents the number of ways to choose m items from n. Then, compute the sum:
For reference, the binomial coefficient C(n,m) is defined as:
where n! = 1 x 2 x 3 x ... x n
Input
Two integers n and m,
where 0<n<15 and 0<m≤n.
Output
One integer — the total number of ways to select up to m items from n distinct items.
Ensure that the output, including formatting 輸出格式, exactly matches the provided samples.
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Write a program to compute the maximum value of the function
f(x,y)=4x−6y
given multiple pairs of integers (x,y).
The computation should be implemented in a function eval_f(iptr, n, index).
-
The first parameter
iptris a list of pointers, each pointing to a pair of integers(x, y). -
The second parameter
nrepresents the number of pairs. -
The third parameter
indexis used to store the position of the pair(x,y)that produces the maximum value of f(x, y).-
For example, if
iptr[3]produces the maximum value of the function, then the integer pointed to byindexshould be set to3. -
If multiple pairs produce the same maximum value,
indexshould store the largest index among them.
-
The program reads several pairs of integers (x, y) until end-of-file (EOF), and prints two integers:
the maximum value and the index (0-based 從零開始) of the pair that produced it.
function to be completed:
int eval_f(int *iptr[], int n, int *index);
main program:
#include <stdio.h>
#define N 256
int eval_f(int *iptr[N], int n, int *index);
int main(void)
{
int n = 0;
int x, y;
int xy[2 * N];
int xy_n = 0;
int max, max_index;
int *iptr[N];
while (scanf("%d%d", &x, &y) != EOF) {
iptr[n] = &(xy[xy_n]);
n++;
xy[xy_n] = x;
xy_n++;
xy[xy_n] = y;
xy_n++;
}
max = eval_f(iptr, n, &max_index);
printf("%d %d\n", max, max_index);
return 0;
}
int eval_f(int *iptr[N], int n, int *index)
{
// Your Task
}
Input
A sequence of integer pairs (x, y) representing the parameters of the function f(x,y)=4x−6y.
The number of pairs n satisfies 0<n≤256.
You should add the EOF (End of File) character at the end of your input in the terminal.
To do this, first press Enter, then press Ctrl + Z, and finally press Enter again.
Output
Two integers:
-
The maximum value of f(x,y).
-
The index of the pair that produced this maximum value.
If multiple pairs give the same maximum value, output the largest index among them.
Ensure that the output, including formatting 輸出格式, exactly matches the provided samples.