Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <locale.h>
- #define MAX 100
- typedef struct Fac{
- int chc;
- } Fac;
- typedef struct Sol{
- double s;
- int chc;
- } Sol;
- void tableoutput1(double* Array, int n, int m, char c);
- void tableoutput2(Sol* a, int n, int m);
- int main(){
- setlocale(LC_ALL, "RUS");
- int n;//number of companies
- int m;//number of resources
- int mm;
- double H[MAX][MAX];//
- Sol S[MAX][MAX];//final profit
- Fac st[MAX];
- printf("Number of concerns:\n");
- scanf("%d", &n);
- printf("Number of resourses:\n");
- scanf("%d", &m);
- int i;
- int int_tmp;
- double double_tmp;
- int j;
- for (j = 0; j < n; j++)
- {
- printf("Charge from (1, ... , %d) resources from the %d concern:\n", m, j + 1);
- for (i = 1; i <= m; i++)
- {
- scanf("%lf", &double_tmp);
- H[i][j] = double_tmp;
- }
- H[0][j] = 0;
- S[0][j].s = 0;
- S[0][j].chc = 0;
- }
- tableoutput1(&H[0][0], n, m, 'H');
- for (i = 0; i <= m; i++)
- {
- S[i][0].s = H[i][n - 1];
- S[i][0].chc = i;
- }
- double smax;
- int k, kmax;
- printf("\n Selection of conditional optimal control:\n");
- for (int j = 1; j < n; j++)
- {
- printf("From %d concerns and folowing\n", n - j);
- printf("___________________\n");
- printf("| y|y-x x| S%d |\n", n - j);
- for (i = 1; i <= m; i++)
- {
- smax = S[i][j - 1].s;
- kmax = 0;
- for (k = 0; k <= i; k++)
- {
- float gh = (H[k][n - j - 1] + S[i - k][j - 1].s);
- printf("___________________\n");
- if (k == 0)
- printf("|%3d|%3d%3d|%7.3lf|\n", i, i - k, k, gh);
- else
- printf("| |%3d%3d|%7.3lf|\n", i - k, k, gh);
- if (gh >= smax)
- {
- smax = H[k][n - j - 1] + S[i - k][j - 1].s;
- kmax = k;
- }
- }
- printf("___________________\n");
- printf("\n");
- S[i][j].s = smax;
- S[i][j].chc = kmax;
- }
- printf("\n\n");
- }
- tableoutput2(S, n, m);
- mm = m;
- st[n - 1].chc = S[m][n - 1].chc;
- for (i = n - 1; i > 0; i--)
- {
- m -= st[i].chc;
- st[i - 1].chc = (S[m][i - 1]).chc;
- }
- int chc;
- printf("\n");
- for (i = 1; i <= n; i++)
- {
- chc = st[i - 1].chc;
- printf("You should invest %d resources to %d concern\n", chc, i);
- }
- printf("\nEarned profit: %lf", S[mm][n - 1]);
- getchar();
- getchar();
- return 0;
- }
- void tableoutput1(double* a, int n, int m, char f){
- printf("\n Table of values of income functions:");
- int i, j;
- printf("\n________");
- for (i = 0; i < n; i++)
- printf("_________");
- printf("\n| x |");
- for (i = 0; i < n; i++)
- printf(" %c%d(x) |", f, i + 1);
- for (j = 0; j <= m; j++)
- {
- printf("\n________");
- for (i = 0; i < n; i++)
- printf("_________");
- printf("\n");
- printf("|%3d |", j);
- for (i = 0; i < n; i++)
- {
- printf("%7.3lf |", *(a + j * MAX + i));
- }
- }
- printf("\n________");
- for (i = 0; i < n; i++)
- printf("_________");
- printf("\n");
- }
- void tableoutput2(Sol* a, int n, int m)
- {
- printf("\n Table of values of charge and conditional optional control:");
- int i, j;
- printf("\n________");
- for (i = 0; i < n; i++)
- printf("_____________");
- printf("\n| y |");
- for (i = 0; i < n; i++)
- printf(" S*%d(y) x* |", i + 1);
- for (j = 0; j <= m; j++)
- {
- printf("\n________");
- for (i = 0; i < n; i++)
- printf("_____________");
- printf("\n");
- printf("|%3d |", j);
- for (i = 0; i < n; i++)
- {
- printf("%7.3lf %3d |", (*(a + j * MAX + i)).s, (*(a + j * MAX + i)).chc);
- }
- }
- printf("\n________");
- for (i = 0; i < n; i++)
- printf("_____________");
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement