|
| 1 | +#include <stdio.h> |
| 2 | +#include "genlib.h" |
| 3 | +#include "simpio.h" |
| 4 | + |
| 5 | +void afairesi(int a,int b,int pl,int number,int table[pl][number],int arxikoCount[pl],int uncoveredCount[pl],int metablitoCount[pl],int col_table[number],int keep); |
| 6 | +bool check(int pl,int uncoveredCount[pl]); |
| 7 | +bool red(int keep,int k,int pl,int number,int table[pl][number],int arxikoCount[pl],int uncoveredCount[pl],int metabalomenoCount[pl],int col_table[number]); |
| 8 | +bool yellow(int k,int keep,int pl,int uncoveredCount[pl],int metabalomenoCount[pl],int number,int col_table[number]); |
| 9 | + |
| 10 | +int main(){ |
| 11 | + int i,j,pl,number,ap; |
| 12 | + printf("Dose sinoliko plithos atomon:"); |
| 13 | + scanf("%d",&pl); |
| 14 | + printf("Dose sinolikes glosses programmatismou:"); |
| 15 | + scanf("%d",&number); |
| 16 | + int table[pl][number]; |
| 17 | + for(i=0; i<pl; i++){ |
| 18 | + for(j=0; j<number; j++){ |
| 19 | + printf("o %d kserei tin glossa programmatismou %d: 0 OXI,1 NAI: ",i+1,j+1); |
| 20 | + scanf("%d",&ap); |
| 21 | + table[i][j] = ap; |
| 22 | + } |
| 23 | + } |
| 24 | + int resaultCover[pl]; |
| 25 | + int uncoveredCount[pl]; |
| 26 | + int arxikoCount[pl]; |
| 27 | + int metabalomenoCount[pl]; |
| 28 | + int col_table[number]; |
| 29 | + int sum = 0; |
| 30 | + for(i=0; i<pl; i++){ |
| 31 | + resaultCover[i] = 0; |
| 32 | + uncoveredCount[i] = 0; |
| 33 | + } |
| 34 | + for(i=0; i<number; i++){ |
| 35 | + for(j=0; j<pl; j++){ |
| 36 | + if(table[j][i] == 1)sum = sum + 1; |
| 37 | + } |
| 38 | + col_table[i] = sum; |
| 39 | + sum = 0; |
| 40 | + } |
| 41 | + for(i=0; i<pl; i++){ |
| 42 | + for(j=0; j<number; j++){ |
| 43 | + if(table[i][j] == 1){ |
| 44 | + uncoveredCount[i]++; |
| 45 | + } |
| 46 | + } |
| 47 | + arxikoCount[i] = uncoveredCount[i]; |
| 48 | + metabalomenoCount[i] = uncoveredCount[i]; |
| 49 | + } |
| 50 | + int keep; |
| 51 | + int max,l; |
| 52 | + int m = 0; |
| 53 | + while(check(pl,uncoveredCount)){ |
| 54 | + max = uncoveredCount[0]; |
| 55 | + keep = 0; |
| 56 | + for(j=1; j<pl; j++){ |
| 57 | + if(uncoveredCount[j]>max){ |
| 58 | + max = uncoveredCount[j]; |
| 59 | + keep = j; |
| 60 | + } |
| 61 | + } |
| 62 | + resaultCover[m] = keep; |
| 63 | + m++; |
| 64 | + afairesi(0,keep,pl,number,table,arxikoCount,uncoveredCount,metabalomenoCount,col_table,keep); |
| 65 | + afairesi(keep+1,pl,pl,number,table,arxikoCount,uncoveredCount,metabalomenoCount,col_table,keep); |
| 66 | + uncoveredCount[keep] = -100; |
| 67 | + for(l=0; l<pl; l++){ |
| 68 | + metabalomenoCount[l] = arxikoCount[l]; |
| 69 | + } |
| 70 | + } |
| 71 | + for(i=0; i<m; i++){ |
| 72 | + printf("Accepted: %d\n",resaultCover[i]+1); |
| 73 | + } |
| 74 | + return 0; |
| 75 | +} |
| 76 | + |
| 77 | +bool check(int pl,int uncoveredCount[pl]){ |
| 78 | + int i,count = 0; |
| 79 | + for(i=0; i<pl; i++){ |
| 80 | + if(uncoveredCount[i]>0)count++; |
| 81 | + } |
| 82 | + if(count>0)return TRUE; |
| 83 | + else return FALSE; |
| 84 | +} |
| 85 | + |
| 86 | +void afairesi(int a,int b,int pl,int number,int table[pl][number],int arxikoCount[pl],int uncoveredCount[pl],int metabalomenoCount[pl],int col_table[number],int keep){ |
| 87 | + int k,l; |
| 88 | + for(k=0; k<number; k++){ |
| 89 | + if(table[keep][k] == 1 && !(red(keep,k,pl,number,table,arxikoCount,uncoveredCount,metabalomenoCount,col_table))){ |
| 90 | + for(l=a; l<b; l++){ |
| 91 | + if(table[l][k] == 1){ |
| 92 | + uncoveredCount[l]--; |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | +bool red(int keep,int k,int pl,int number,int table[pl][number],int arxikoCount[pl],int uncoveredCount[pl],int metabalomenoCount[pl],int col_table[number]){ |
| 100 | + if(table[keep][k] == 1 && yellow(k,keep,pl,uncoveredCount,metabalomenoCount,number,col_table)){ |
| 101 | + return TRUE; |
| 102 | + } |
| 103 | + else return FALSE; |
| 104 | +} |
| 105 | + |
| 106 | +bool yellow(int k,int keep,int pl,int uncoveredCount[pl],int metabalomenoCount[pl],int number,int col_table[number]){ |
| 107 | + if(metabalomenoCount[keep] != uncoveredCount[keep]){ |
| 108 | + metabalomenoCount[keep]--; |
| 109 | + return TRUE; |
| 110 | + } |
| 111 | + else{ |
| 112 | + if(col_table[k] == 1)return TRUE; |
| 113 | + return FALSE; |
| 114 | + } |
| 115 | +} |
| 116 | + |
| 117 | + |
0 commit comments