Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <conio.h>
- #define wplecak 8
- #define welement 5
- using namespace std;
- int main(int argc, char *argv[])
- {
- int i,j,a,b;
- int elementy[welement+1][2]=
- {{0,0},{3,4},{2,4},{3,2},{1,2},{2,3}}; //WIELKOSCI ELEMENTOW I ICH WARTOSCI
- int c[welement+1][wplecak+1]; //TABILCA WYNIKOW SUMY ELEMENTOW W PLECAKU
- // ************* ZEROWANIE TABLICY WYNIKOW *************
- for(i=0;i<welement+1;i++)
- for(j=0;j<wplecak+1;j++)
- c [j]=0;
- // ************* CZYSZCZENIE EKRANU *************
- system("cls");
- // *************** SITO SPRAWDZAJACE MOZLIWOSC UMIESZCZENIA ELEMENTOW **************
- // ************* W "PLECAKU" ORAZ WPISANIE WARTOSCI DO TABLICY WYNIKOW *************
- for(i=0;i<welement+1;i++)
- for(j=0;j<wplecak+1;j++)
- {
- if(elementy [0]<=j)
- {
- a=c[i-1][j];
- b=elementy [1]+c[i-1][j-(elementy [0])];
- if(a>b) c [j]=a;
- else c [j]=b;
- }
- if(elementy [0]>j)
- {
- c [j]=c[i-1][j];
- }
- if(j==0 // i==0)
- {
- c [j] = 0;
- }
- }
- // ************* WYSWIETLANIE WPISOW TABLICY NA EKRANIE *************
- for(i=0;i<welement+1;i++)
- {
- for(j=0;j<wplecak+1;j++)
- {
- cout <<i<<","<<j<<"="<<c [j]<<" ";
- }
- cout << "
- ";
- }
- getch();
- system("PAUSE");
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement