text
stringlengths 0
82
|
---|
ORG 0000H |
LJMP MAIN |
ORG 30H |
MAIN: |
CLR P1.2 |
MOV A ,#15H |
MOV R0,A |
MOV B, #10H |
DIV AB |
MOV A,B |
MOV R1,A |
MOV A,R0 |
SWAP A |
MOV B,#10H |
DIV AB |
MOV A,B |
MOV R2,A |
ACALL CALC |
ACALL CHECK |
CALC: |
MOV A , R1 |
MOV B, R1 |
MUL AB |
MOV B,R1 |
MUL AB |
MOV R3,A |
MOV A , R2 |
MOV B, R2 |
MUL AB |
MOV B,R2 |
MUL AB |
MOV R4,A |
MOV A,R3 |
MOV B,R4 |
ADD A,B |
RET |
CHECK: |
CLR P1.2 |
MOV B,R0 |
CJNE A,B ,NOWAVE |
WAVE: |
AGAIN: |
SETB P1.2 |
SJMP AGAIN |
NOWAVE: |
NOAGAIN: |
CLR P1.2 |
SJMP NOAGAIN |
END |
0/1 Knapsack DP |
#include <stdio.h> |
#include <limits.h> |
void knapsack(int n, int m, int profits[], int weights[]) |
{ |
int v[n+1][m+1]; |
int result[n]; |
for(int i=0; i<=m; i++) |
v[0][i] = 0; |
for(int i=0; i<=n; i++) |
v[i][0] = 0; |
for(int i=1; i<=n; i++) { |
for(int w=1; w<=m; w++) { |
if(w - weights[i-1] <0) { |
v[i][w] = v[i-1][w]; |
} else { |
int val1 = v[i-1][w]; |
int val2 = v[i-1][w-weights[i-1]] + profits[i-1]; |
v[i][w] = (val1 > val2) ? val1 : val2; |
} |
} |
} |
int k=n, j=m; |
while (k>0 && j>0) { |
if(v[k][j] != v[k-1][j]) { |
result[k-1] = 1; |
j = j-weights[k-1]; |
} |
else { |
result[k-1] = 0; |
} |
k--; |
} |
for(int i=0; i<n; i++) |
printf("%d ", result[i]); |
} |
int main() |
{ |
int n; //No. of objects |
scanf("%d", &n); |
int m; //Max capacity |
scanf("%d", &m); |
End of preview. Expand
in Dataset Viewer.
No dataset card yet
New: Create and edit this dataset card directly on the website!
Contribute a Dataset Card- Downloads last month
- 37