submission_id
stringlengths 10
10
| problem_id
stringlengths 6
6
| language
stringclasses 3
values | code
stringlengths 1
522k
| compiler_output
stringlengths 43
10.2k
|
|---|---|---|---|---|
s328239101
|
p00042
|
C
|
const int MAX_N = 1000; // n????????§???
const int MAX_W = 5000; // W????????§???
// ??\???
int n, W;
int w[MAX_N], v[MAX_N];
// ?????¢??????????????????
// dp[i][j]???i????????\?????????????????????????????????j??\?????????????????????????????¨??????????????????????????§????????¨??????
// -1????????????????±??????§???????????¨?????¨???
int dp[MAX_N + 1][MAX_W + 1];
// i????????\?????????????????????????????????j??\?????????????????????????????¨?????????
// ???????????????????????????????????§??????????????¢??°
int rec_dp(int i, int j) {
if (dp[i][j] != -1) {
// ?????§?????????????????¨??????????????????????????????????????¨
return dp[i][j];
}
int res;
if (i == n) {
// ????????????????????£??????????????¨?????????????????????????????§??????0??§?¢????
res = 0;
} else if (j < w[i]) {
// ???????????????????¶?????????????i?????\????????????????????§?????\?????????????????????????????????
res = rec_dp(i + 1, j);
} else {
// ??????i?????\???????????\??????????????????????????§???????????????????????????????????§?????????????????¶
res = max(
rec_dp(i + 1, j),
rec_dp(i + 1, j - w[i]) + v[i]
);
}
// ?????????????????????????¨???¶??????
return dp[i][j] = res;
}
void solve_dp() {
memset(dp, -1, sizeof(dp)); // ?????¢??????????????????-1??§??????????????\??????for???????????¨??????
// for (int i = 0; i < MAX_N + 1; i++)
// for (int j = 0; j < MAX_W + 1; j++)
// dp[i][j] = -1;
// 0????????\?????§??????W??\????????´?????????????????¨?????????
cout << rec_dp(0, W) << endl;
}
|
main.c:6:5: error: variably modified 'w' at file scope
6 | int w[MAX_N], v[MAX_N];
| ^
main.c:6:15: error: variably modified 'v' at file scope
6 | int w[MAX_N], v[MAX_N];
| ^
main.c:11:5: error: variably modified 'dp' at file scope
11 | int dp[MAX_N + 1][MAX_W + 1];
| ^~
main.c:11:5: error: variably modified 'dp' at file scope
main.c: In function 'rec_dp':
main.c:29:11: error: implicit declaration of function 'max' [-Wimplicit-function-declaration]
29 | res = max(
| ^~~
main.c: In function 'solve_dp':
main.c:39:3: error: implicit declaration of function 'memset' [-Wimplicit-function-declaration]
39 | memset(dp, -1, sizeof(dp)); // ?????¢??????????????????-1??§??????????????\??????for???????????¨??????
| ^~~~~~
main.c:1:1: note: include '<string.h>' or provide a declaration of 'memset'
+++ |+#include <string.h>
1 | const int MAX_N = 1000; // n????????§???
main.c:39:3: warning: incompatible implicit declaration of built-in function 'memset' [-Wbuiltin-declaration-mismatch]
39 | memset(dp, -1, sizeof(dp)); // ?????¢??????????????????-1??§??????????????\??????for???????????¨??????
| ^~~~~~
main.c:39:3: note: include '<string.h>' or provide a declaration of 'memset'
main.c:45:3: error: 'cout' undeclared (first use in this function)
45 | cout << rec_dp(0, W) << endl;
| ^~~~
main.c:45:3: note: each undeclared identifier is reported only once for each function it appears in
main.c:45:27: error: 'endl' undeclared (first use in this function)
45 | cout << rec_dp(0, W) << endl;
| ^~~~
|
s340269876
|
p00042
|
C
|
const int MAX_N = 1000; // n????????§???
const int MAX_W = 5000; // W????????§???
// ??\???
int n, W;
int w[MAX_N], v[MAX_N];
// DP????????????
// dp[i][j]???i????????\?????????????????????????????????j??\?????????????????????????????¨??????????????????????????§????????¨??????
int dp[MAX_N + 1][MAX_W + 1];
void solve_dp2() {
for (int j = 0; j <= W; j++) {
dp[n][j] = 0;
}
for (int i = n - 1; i >= 0; i--) {
for (int j = 0; j <= W; j++) {
if (j < w[i])
dp[i][j] = dp[i + 1][j];
else
dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
}
}
cout << dp[0][W] << endl;
}
|
main.c:6:5: error: variably modified 'w' at file scope
6 | int w[MAX_N], v[MAX_N];
| ^
main.c:6:15: error: variably modified 'v' at file scope
6 | int w[MAX_N], v[MAX_N];
| ^
main.c:10:5: error: variably modified 'dp' at file scope
10 | int dp[MAX_N + 1][MAX_W + 1];
| ^~
main.c:10:5: error: variably modified 'dp' at file scope
main.c: In function 'solve_dp2':
main.c:21:20: error: implicit declaration of function 'max' [-Wimplicit-function-declaration]
21 | dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
| ^~~
main.c:24:3: error: 'cout' undeclared (first use in this function)
24 | cout << dp[0][W] << endl;
| ^~~~
main.c:24:3: note: each undeclared identifier is reported only once for each function it appears in
main.c:24:23: error: 'endl' undeclared (first use in this function)
24 | cout << dp[0][W] << endl;
| ^~~~
|
s323993604
|
p00042
|
C
|
a
|
main.c:1:1: error: expected '=', ',', ';', 'asm' or '__attribute__' at end of input
1 | a
| ^
|
s313072551
|
p00042
|
C
|
t[9999][9999],j;main(p,W,a,b,c){
for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){
for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--){
for(j=0;j<=W;j++){
t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);
}
}
for(j=0;t[0][j]==t[0][W];j++)
}
}
|
main.c:1:1: warning: data definition has no type or storage class
1 | t[9999][9999],j;main(p,W,a,b,c){
| ^
main.c:1:1: error: type defaults to 'int' in declaration of 't' [-Wimplicit-int]
main.c:1:15: error: type defaults to 'int' in declaration of 'j' [-Wimplicit-int]
1 | t[9999][9999],j;main(p,W,a,b,c){
| ^
main.c:1:17: error: return type defaults to 'int' [-Wimplicit-int]
1 | t[9999][9999],j;main(p,W,a,b,c){
| ^~~~
main.c: In function 'main':
main.c:1:17: error: type of 'p' defaults to 'int' [-Wimplicit-int]
main.c:1:17: error: type of 'W' defaults to 'int' [-Wimplicit-int]
main.c:1:17: error: type of 'a' defaults to 'int' [-Wimplicit-int]
main.c:1:17: error: type of 'b' defaults to 'int' [-Wimplicit-int]
main.c:1:17: error: type of 'c' defaults to 'int' [-Wimplicit-int]
main.c:2:6: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
2 | for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){
| ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
+++ |+#include <stdio.h>
1 | t[9999][9999],j;main(p,W,a,b,c){
main.c:2:6: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
2 | for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){
| ^~~~~
main.c:2:6: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:2:23: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
2 | for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){
| ^~~~~~
main.c:2:23: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:2:23: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:2:23: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:9:9: error: expected expression before '}' token
9 | }
| ^
|
s343232980
|
p00042
|
C
|
t[9999][9999],j;main(p,W,a,b,c){
for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){
for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--){
for(j=0;j<=W;j++){
t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);
}
}
for(j=0;t[0][j]==t[0][W];j++)
}
return 0;
}
|
main.c:1:1: warning: data definition has no type or storage class
1 | t[9999][9999],j;main(p,W,a,b,c){
| ^
main.c:1:1: error: type defaults to 'int' in declaration of 't' [-Wimplicit-int]
main.c:1:15: error: type defaults to 'int' in declaration of 'j' [-Wimplicit-int]
1 | t[9999][9999],j;main(p,W,a,b,c){
| ^
main.c:1:17: error: return type defaults to 'int' [-Wimplicit-int]
1 | t[9999][9999],j;main(p,W,a,b,c){
| ^~~~
main.c: In function 'main':
main.c:1:17: error: type of 'p' defaults to 'int' [-Wimplicit-int]
main.c:1:17: error: type of 'W' defaults to 'int' [-Wimplicit-int]
main.c:1:17: error: type of 'a' defaults to 'int' [-Wimplicit-int]
main.c:1:17: error: type of 'b' defaults to 'int' [-Wimplicit-int]
main.c:1:17: error: type of 'c' defaults to 'int' [-Wimplicit-int]
main.c:2:6: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
2 | for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){
| ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
+++ |+#include <stdio.h>
1 | t[9999][9999],j;main(p,W,a,b,c){
main.c:2:6: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
2 | for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){
| ^~~~~
main.c:2:6: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:2:23: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
2 | for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){
| ^~~~~~
main.c:2:23: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:2:23: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:2:23: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:9:9: error: expected expression before '}' token
9 | }
| ^
|
s126399717
|
p00042
|
C
|
table[9999][9999],j;
main(p,W,a,b,c){
for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,table[0][W],j)){
for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--){
for(j=0;j<=W;j++){
table[c-1][j]=(j<a)?table[c][j]:(table[c][j]>table[c][j-a]+b)?table[c][j]:(table[c][j-a]+b);
}
}
for(j=0;table[0][j]==table[0][W];j++)
}
}
|
main.c:1:1: warning: data definition has no type or storage class
1 | table[9999][9999],j;
| ^~~~~
main.c:1:1: error: type defaults to 'int' in declaration of 'table' [-Wimplicit-int]
main.c:1:19: error: type defaults to 'int' in declaration of 'j' [-Wimplicit-int]
1 | table[9999][9999],j;
| ^
main.c:2:1: error: return type defaults to 'int' [-Wimplicit-int]
2 | main(p,W,a,b,c){
| ^~~~
main.c: In function 'main':
main.c:2:1: error: type of 'p' defaults to 'int' [-Wimplicit-int]
main.c:2:1: error: type of 'W' defaults to 'int' [-Wimplicit-int]
main.c:2:1: error: type of 'a' defaults to 'int' [-Wimplicit-int]
main.c:2:1: error: type of 'b' defaults to 'int' [-Wimplicit-int]
main.c:2:1: error: type of 'c' defaults to 'int' [-Wimplicit-int]
main.c:3:14: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
3 | for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,table[0][W],j)){
| ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
+++ |+#include <stdio.h>
1 | table[9999][9999],j;
main.c:3:14: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
3 | for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,table[0][W],j)){
| ^~~~~
main.c:3:14: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:3:31: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
3 | for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,table[0][W],j)){
| ^~~~~~
main.c:3:31: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:3:31: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:3:31: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:10:9: error: expected expression before '}' token
10 | }
| ^
|
s378143332
|
p00042
|
C
|
table[9999][9999],j;
main(p,W,a,b,c){
for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,table[0][W],j)){
for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--){
for(j=0;j<=W;j++){
table[c-1][j]=(j<a)?table[c][j]:(table[c][j]>table[c][j-a]+b)?table[c][j]:(table[c][j-a]+b);
}
}
for(j=0;table[0][j]==table[0][W];j++)
}
return 0;
}
|
main.c:1:1: warning: data definition has no type or storage class
1 | table[9999][9999],j;
| ^~~~~
main.c:1:1: error: type defaults to 'int' in declaration of 'table' [-Wimplicit-int]
main.c:1:19: error: type defaults to 'int' in declaration of 'j' [-Wimplicit-int]
1 | table[9999][9999],j;
| ^
main.c:2:1: error: return type defaults to 'int' [-Wimplicit-int]
2 | main(p,W,a,b,c){
| ^~~~
main.c: In function 'main':
main.c:2:1: error: type of 'p' defaults to 'int' [-Wimplicit-int]
main.c:2:1: error: type of 'W' defaults to 'int' [-Wimplicit-int]
main.c:2:1: error: type of 'a' defaults to 'int' [-Wimplicit-int]
main.c:2:1: error: type of 'b' defaults to 'int' [-Wimplicit-int]
main.c:2:1: error: type of 'c' defaults to 'int' [-Wimplicit-int]
main.c:3:14: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
3 | for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,table[0][W],j)){
| ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
+++ |+#include <stdio.h>
1 | table[9999][9999],j;
main.c:3:14: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
3 | for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,table[0][W],j)){
| ^~~~~
main.c:3:14: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:3:31: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
3 | for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,table[0][W],j)){
| ^~~~~~
main.c:3:31: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:3:31: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:3:31: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:10:9: error: expected expression before '}' token
10 | }
| ^
|
s053981177
|
p00042
|
C
|
table[9999][9999],j;
main(p,W,a,b,c){
for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,table[0][W],j)){
for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--){
for(j=0;j<=W;j++){
table[c-1][j]=(j<a)?table[c][j]:(table[c][j]>table[c][j-a]+b)?table[c][j]:(table[c][j-a]+b);
}
}
for(j=0;table[0][j]!=table[0][W];j++)
}
return 0;
}
|
main.c:1:1: warning: data definition has no type or storage class
1 | table[9999][9999],j;
| ^~~~~
main.c:1:1: error: type defaults to 'int' in declaration of 'table' [-Wimplicit-int]
main.c:1:19: error: type defaults to 'int' in declaration of 'j' [-Wimplicit-int]
1 | table[9999][9999],j;
| ^
main.c:2:1: error: return type defaults to 'int' [-Wimplicit-int]
2 | main(p,W,a,b,c){
| ^~~~
main.c: In function 'main':
main.c:2:1: error: type of 'p' defaults to 'int' [-Wimplicit-int]
main.c:2:1: error: type of 'W' defaults to 'int' [-Wimplicit-int]
main.c:2:1: error: type of 'a' defaults to 'int' [-Wimplicit-int]
main.c:2:1: error: type of 'b' defaults to 'int' [-Wimplicit-int]
main.c:2:1: error: type of 'c' defaults to 'int' [-Wimplicit-int]
main.c:3:14: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
3 | for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,table[0][W],j)){
| ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
+++ |+#include <stdio.h>
1 | table[9999][9999],j;
main.c:3:14: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
3 | for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,table[0][W],j)){
| ^~~~~
main.c:3:14: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:3:31: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
3 | for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,table[0][W],j)){
| ^~~~~~
main.c:3:31: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:3:31: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:3:31: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:10:9: error: expected expression before '}' token
10 | }
| ^
|
s188922731
|
p00042
|
C
|
table[9999][9999],j;
main(p,W,a,b,c){
for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,table[0][W],j)){
for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--){
for(j=0;j<=W;j++){
table[c-1][j]=(j<a)?table[c][j]:(table[c][j]>table[c][j-a]+b)?table[c][j]:(table[c][j-a]+b);
}
}
for(j=0;table[0][j]!=table[0][W];j++)
}
return 0;
}
|
main.c:1:1: warning: data definition has no type or storage class
1 | table[9999][9999],j;
| ^~~~~
main.c:1:1: error: type defaults to 'int' in declaration of 'table' [-Wimplicit-int]
main.c:1:19: error: type defaults to 'int' in declaration of 'j' [-Wimplicit-int]
1 | table[9999][9999],j;
| ^
main.c:2:1: error: return type defaults to 'int' [-Wimplicit-int]
2 | main(p,W,a,b,c){
| ^~~~
main.c: In function 'main':
main.c:2:1: error: type of 'p' defaults to 'int' [-Wimplicit-int]
main.c:2:1: error: type of 'W' defaults to 'int' [-Wimplicit-int]
main.c:2:1: error: type of 'a' defaults to 'int' [-Wimplicit-int]
main.c:2:1: error: type of 'b' defaults to 'int' [-Wimplicit-int]
main.c:2:1: error: type of 'c' defaults to 'int' [-Wimplicit-int]
main.c:3:14: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
3 | for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,table[0][W],j)){
| ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
+++ |+#include <stdio.h>
1 | table[9999][9999],j;
main.c:3:14: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
3 | for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,table[0][W],j)){
| ^~~~~
main.c:3:14: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:3:31: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
3 | for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,table[0][W],j)){
| ^~~~~~
main.c:3:31: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:3:31: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:3:31: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:10:9: error: expected expression before '}' token
10 | }
| ^
|
s668563056
|
p00042
|
C
|
t[][],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}}
|
main.c:1:1: warning: data definition has no type or storage class
1 | t[][],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}}
| ^
main.c:1:1: error: type defaults to 'int' in declaration of 't' [-Wimplicit-int]
main.c:1:1: error: array type has incomplete element type 'int[]'
main.c:1:1: note: declaration of 't' as multidimensional array must have bounds for all dimensions except the first
main.c:1:7: error: type defaults to 'int' in declaration of 'j' [-Wimplicit-int]
1 | t[][],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}}
| ^
main.c:1:9: error: return type defaults to 'int' [-Wimplicit-int]
1 | t[][],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}}
| ^~~~
main.c: In function 'main':
main.c:1:9: error: type of 'p' defaults to 'int' [-Wimplicit-int]
main.c:1:9: error: type of 'W' defaults to 'int' [-Wimplicit-int]
main.c:1:9: error: type of 'a' defaults to 'int' [-Wimplicit-int]
main.c:1:9: error: type of 'b' defaults to 'int' [-Wimplicit-int]
main.c:1:9: error: type of 'c' defaults to 'int' [-Wimplicit-int]
main.c:1:30: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
1 | t[][],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}}
| ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
+++ |+#include <stdio.h>
1 | t[][],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}}
main.c:1:30: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
1 | t[][],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}}
| ^~~~~
main.c:1:30: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:1:47: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
1 | t[][],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}}
| ^~~~~~
main.c:1:47: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:1:47: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:1:47: note: include '<stdio.h>' or provide a declaration of 'printf'
|
s518756060
|
p00042
|
C
|
t[1e9][1e9],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}}
|
main.c:1:1: warning: data definition has no type or storage class
1 | t[1e9][1e9],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}}
| ^
main.c:1:1: error: type defaults to 'int' in declaration of 't' [-Wimplicit-int]
main.c:1:1: error: size of array 't' has non-integer type
main.c:1:1: error: size of array 't' has non-integer type
main.c:1:13: error: type defaults to 'int' in declaration of 'j' [-Wimplicit-int]
1 | t[1e9][1e9],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}}
| ^
main.c:1:15: error: return type defaults to 'int' [-Wimplicit-int]
1 | t[1e9][1e9],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}}
| ^~~~
main.c: In function 'main':
main.c:1:15: error: type of 'p' defaults to 'int' [-Wimplicit-int]
main.c:1:15: error: type of 'W' defaults to 'int' [-Wimplicit-int]
main.c:1:15: error: type of 'a' defaults to 'int' [-Wimplicit-int]
main.c:1:15: error: type of 'b' defaults to 'int' [-Wimplicit-int]
main.c:1:15: error: type of 'c' defaults to 'int' [-Wimplicit-int]
main.c:1:36: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
1 | t[1e9][1e9],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}}
| ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
+++ |+#include <stdio.h>
1 | t[1e9][1e9],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}}
main.c:1:36: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
1 | t[1e9][1e9],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}}
| ^~~~~
main.c:1:36: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:1:53: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
1 | t[1e9][1e9],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}}
| ^~~~~~
main.c:1:53: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:1:53: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:1:53: note: include '<stdio.h>' or provide a declaration of 'printf'
|
s654149731
|
p00042
|
C
|
t[9e9][9e9],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}}
|
main.c:1:1: warning: data definition has no type or storage class
1 | t[9e9][9e9],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}}
| ^
main.c:1:1: error: type defaults to 'int' in declaration of 't' [-Wimplicit-int]
main.c:1:1: error: size of array 't' has non-integer type
main.c:1:1: error: size of array 't' has non-integer type
main.c:1:13: error: type defaults to 'int' in declaration of 'j' [-Wimplicit-int]
1 | t[9e9][9e9],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}}
| ^
main.c:1:15: error: return type defaults to 'int' [-Wimplicit-int]
1 | t[9e9][9e9],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}}
| ^~~~
main.c: In function 'main':
main.c:1:15: error: type of 'p' defaults to 'int' [-Wimplicit-int]
main.c:1:15: error: type of 'W' defaults to 'int' [-Wimplicit-int]
main.c:1:15: error: type of 'a' defaults to 'int' [-Wimplicit-int]
main.c:1:15: error: type of 'b' defaults to 'int' [-Wimplicit-int]
main.c:1:15: error: type of 'c' defaults to 'int' [-Wimplicit-int]
main.c:1:36: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
1 | t[9e9][9e9],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}}
| ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
+++ |+#include <stdio.h>
1 | t[9e9][9e9],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}}
main.c:1:36: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
1 | t[9e9][9e9],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}}
| ^~~~~
main.c:1:36: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:1:53: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
1 | t[9e9][9e9],j;main(p,W,a,b,c){for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=(j<a)?t[c][j]:(t[c][j]>t[c][j-a]+b)?t[c][j]:(t[c][j-a]+b);for(j=0;t[0][j]-t[0][W];j++);}}
| ^~~~~~
main.c:1:53: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:1:53: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:1:53: note: include '<stdio.h>' or provide a declaration of 'printf'
|
s584931289
|
p00042
|
C
|
t[9999][9999],j;main(p,W,a,b,c){
for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){
for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=j<a?t[c][j]fmax(t[c][j],(t[c][j-a]+b));
for(j=0;t[0][j]==t[0][W];j++);
}
}
|
main.c:1:1: warning: data definition has no type or storage class
1 | t[9999][9999],j;main(p,W,a,b,c){
| ^
main.c:1:1: error: type defaults to 'int' in declaration of 't' [-Wimplicit-int]
main.c:1:15: error: type defaults to 'int' in declaration of 'j' [-Wimplicit-int]
1 | t[9999][9999],j;main(p,W,a,b,c){
| ^
main.c:1:17: error: return type defaults to 'int' [-Wimplicit-int]
1 | t[9999][9999],j;main(p,W,a,b,c){
| ^~~~
main.c: In function 'main':
main.c:1:17: error: type of 'p' defaults to 'int' [-Wimplicit-int]
main.c:1:17: error: type of 'W' defaults to 'int' [-Wimplicit-int]
main.c:1:17: error: type of 'a' defaults to 'int' [-Wimplicit-int]
main.c:1:17: error: type of 'b' defaults to 'int' [-Wimplicit-int]
main.c:1:17: error: type of 'c' defaults to 'int' [-Wimplicit-int]
main.c:2:6: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
2 | for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){
| ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
+++ |+#include <stdio.h>
1 | t[9999][9999],j;main(p,W,a,b,c){
main.c:2:6: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
2 | for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){
| ^~~~~
main.c:2:6: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:2:23: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
2 | for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){
| ^~~~~~
main.c:2:23: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:2:23: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:2:23: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:3:102: error: expected ':' before 'fmax'
3 | for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--)for(j=0;j<=W;j++)t[c-1][j]=j<a?t[c][j]fmax(t[c][j],(t[c][j-a]+b));
| ^~~~
| :
|
s056116383
|
p00042
|
C
|
t[9999][9999],j;main(p,W,a,b,c){
for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){
for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);j=c--)for(j=0;j<=W;j++)t[c-1][j]=j<a?t[c][j]fmax(t[c][j],(t[c][j-a]+b));
for(;t[0][++j]!=t[0][W];);
}
}
|
main.c:2:1: warning: data definition has no type or storage class
2 | t[9999][9999],j;main(p,W,a,b,c){
| ^
main.c:2:1: error: type defaults to 'int' in declaration of 't' [-Wimplicit-int]
main.c:2:15: error: type defaults to 'int' in declaration of 'j' [-Wimplicit-int]
2 | t[9999][9999],j;main(p,W,a,b,c){
| ^
main.c:2:17: error: return type defaults to 'int' [-Wimplicit-int]
2 | t[9999][9999],j;main(p,W,a,b,c){
| ^~~~
main.c: In function 'main':
main.c:2:17: error: type of 'p' defaults to 'int' [-Wimplicit-int]
main.c:2:17: error: type of 'W' defaults to 'int' [-Wimplicit-int]
main.c:2:17: error: type of 'a' defaults to 'int' [-Wimplicit-int]
main.c:2:17: error: type of 'b' defaults to 'int' [-Wimplicit-int]
main.c:2:17: error: type of 'c' defaults to 'int' [-Wimplicit-int]
main.c:3:6: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
3 | for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){
| ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
+++ |+#include <stdio.h>
1 |
main.c:3:6: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
3 | for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){
| ^~~~~
main.c:3:6: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:3:23: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
3 | for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,t[0][W],j)){
| ^~~~~~
main.c:3:23: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:3:23: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:3:23: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:4:104: error: expected ':' before 'fmax'
4 | for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);j=c--)for(j=0;j<=W;j++)t[c-1][j]=j<a?t[c][j]fmax(t[c][j],(t[c][j-a]+b));
| ^~~~
| :
|
s712019486
|
p00042
|
C
|
t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
|
main.c:1:1: warning: data definition has no type or storage class
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^
main.c:1:1: error: type defaults to 'int' in declaration of 't' [-Wimplicit-int]
main.c:1:9: error: type defaults to 'int' in declaration of 'W' [-Wimplicit-int]
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^
main.c:1:11: error: type defaults to 'int' in declaration of 'N' [-Wimplicit-int]
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^
main.c:1:13: error: type defaults to 'int' in declaration of 'a' [-Wimplicit-int]
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^
main.c:1:15: error: type defaults to 'int' in declaration of 'b' [-Wimplicit-int]
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^
main.c:1:17: error: return type defaults to 'int' [-Wimplicit-int]
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^~~~
main.c: In function 'main':
main.c:1:17: error: type of 'c' defaults to 'int' [-Wimplicit-int]
main.c:1:30: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
+++ |+#include <stdio.h>
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
main.c:1:30: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^~~~~
main.c:1:30: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:1:52: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^~~~~~
main.c:1:52: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:1:52: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:1:52: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:1:89: error: 'i' undeclared (first use in this function)
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^
main.c:1:89: note: each undeclared identifier is reported only once for each function it appears in
main.c:1:92: error: implicit declaration of function 'bzero' [-Wimplicit-function-declaration]
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^~~~~
main.c:1:92: warning: incompatible implicit declaration of built-in function 'bzero' [-Wbuiltin-declaration-mismatch]
main.c:1:157: error: implicit declaration of function 'fmax' [-Wimplicit-function-declaration]
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^~~~
main.c:1:1: note: include '<math.h>' or provide a declaration of 'fmax'
+++ |+#include <math.h>
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
main.c:1:157: warning: incompatible implicit declaration of built-in function 'fmax' [-Wbuiltin-declaration-mismatch]
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^~~~
main.c:1:157: note: include '<math.h>' or provide a declaration of 'fmax'
|
s136109405
|
p00042
|
C
|
t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
|
main.c:1:1: warning: data definition has no type or storage class
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^
main.c:1:1: error: type defaults to 'int' in declaration of 't' [-Wimplicit-int]
main.c:1:9: error: type defaults to 'int' in declaration of 'W' [-Wimplicit-int]
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^
main.c:1:11: error: type defaults to 'int' in declaration of 'N' [-Wimplicit-int]
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^
main.c:1:13: error: type defaults to 'int' in declaration of 'a' [-Wimplicit-int]
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^
main.c:1:15: error: type defaults to 'int' in declaration of 'b' [-Wimplicit-int]
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^
main.c:1:17: error: return type defaults to 'int' [-Wimplicit-int]
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^~~~
main.c: In function 'main':
main.c:1:17: error: type of 'c' defaults to 'int' [-Wimplicit-int]
main.c:1:30: error: implicit declaration of function 'scanf' [-Wimplicit-function-declaration]
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^~~~~
main.c:1:1: note: include '<stdio.h>' or provide a declaration of 'scanf'
+++ |+#include <stdio.h>
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
main.c:1:30: warning: incompatible implicit declaration of built-in function 'scanf' [-Wbuiltin-declaration-mismatch]
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^~~~~
main.c:1:30: note: include '<stdio.h>' or provide a declaration of 'scanf'
main.c:1:52: error: implicit declaration of function 'printf' [-Wimplicit-function-declaration]
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^~~~~~
main.c:1:52: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:1:52: warning: incompatible implicit declaration of built-in function 'printf' [-Wbuiltin-declaration-mismatch]
main.c:1:52: note: include '<stdio.h>' or provide a declaration of 'printf'
main.c:1:89: error: 'i' undeclared (first use in this function)
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^
main.c:1:89: note: each undeclared identifier is reported only once for each function it appears in
main.c:1:92: error: implicit declaration of function 'bzero' [-Wimplicit-function-declaration]
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^~~~~
main.c:1:92: warning: incompatible implicit declaration of built-in function 'bzero' [-Wbuiltin-declaration-mismatch]
main.c:1:157: error: implicit declaration of function 'fmax' [-Wimplicit-function-declaration]
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^~~~
main.c:1:1: note: include '<math.h>' or provide a declaration of 'fmax'
+++ |+#include <math.h>
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
main.c:1:157: warning: incompatible implicit declaration of built-in function 'fmax' [-Wbuiltin-declaration-mismatch]
1 | t[9999],W,N,a,b;main(c){for(;scanf("%d%d",&W,&N)-1;printf("Case %d:\n%d\n%d\n",c++,t[W],i),bzero(t,W*9)){for(;N--&&scanf("%d,%d",&a,&b);)for(i=W;i>=b;)t[i]=fmax(t[i--],t[i-b]+a);for(i=0;t[++i]-t[W];i);}}
| ^~~~
main.c:1:157: note: include '<math.h>' or provide a declaration of 'fmax'
|
s864666550
|
p00042
|
C
|
#include <stdio.h>
main(){
int i,j,W,w,n,a[1000],b[1000],c[1000],maxc,minb,aa,ans,c;
c=0;
while(1){
c++;
scanf("%d",&W);
if(W==0) break;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d,%d",&a[i],&b[i]);
c[i]=a[i]/b[i];
}
w=0;
ans=0;
maxc=0;
minb=1001;
while(W>w){
for(i=0;i<n;i++){
if(maxc<c[i] && minb>b[i] && b[i]!=0){
maxc=c[i];
minb=b[i];
aa=i;
}
}
w+=minb;
c[aa]=0;
b[aa]=0;
}
w-=minb;
}
return 0;
}
|
main.c:2:1: error: return type defaults to 'int' [-Wimplicit-int]
2 | main(){
| ^~~~
main.c: In function 'main':
main.c:3:58: error: conflicting types for 'c'; have 'int'
3 | int i,j,W,w,n,a[1000],b[1000],c[1000],maxc,minb,aa,ans,c;
| ^
main.c:3:33: note: previous declaration of 'c' with type 'int[1000]'
3 | int i,j,W,w,n,a[1000],b[1000],c[1000],maxc,minb,aa,ans,c;
| ^
|
s729746159
|
p00042
|
C
|
#include <cstdio>
#include <algorithm>
using namespace std;
const int MAX_N = 1010;
const int MAX_W = 1010;
int memo[MAX_N][MAX_W];
int W, N, v[MAX_N], w[MAX_N], min_w;
int main()
{
for(int c = 1; ~scanf("%d", &W) && W; ++c)
{
scanf("%d", &N);
for(int i = 0; i < N; ++i)
scanf("%d,%d", v+i, w+i);
fill_n(memo[N], W+1, 0);
for(int i = N - 1; i >= 0; --i)
for(int j = 0; j <= W; ++j)
if(j < w[i])
memo[i][j] = memo[i+1][j];
else
memo[i][j] = max(memo[i+1][j], memo[i+1][j-w[i]] + v[i]);
min_w = W;
while(memo[0][W] == memo[0][min_w-1])
--min_w;
printf("Case %d:\n%d\n%d\n", c, memo[0][W], min_w);
}
}
|
main.c:1:10: fatal error: cstdio: No such file or directory
1 | #include <cstdio>
| ^~~~~~~~
compilation terminated.
|
s768891314
|
p00042
|
C
|
#include <stdio.h>
#include <vector>
#include <algorithm>
#define TEST 1
typedef std::pair<int,int> pi;
struct Pred
{
bool operator()(const pi& f,const pi& s)//<
{
return f.second > s.second;
}
};
pi rec_check(const std::vector<pi> &data,int start,int remw)
{
if(start >=data.size() )
return pi(0,0);
if(data[start].second > remw)
return rec_check(data,start+1,remw);
pi div0= rec_check(data,start + 1,remw - data[start].second);
div0.first+=data[start].first;
div0.second+=data[start].second;
pi div1 = rec_check(data,start + 1,remw);
if(div0.first > div1.first )
return div0;
if(div0.first < div1.first)
return div1;
if(div0.second <div1.second)
return div0;
return div1;
}
int main(void)
{
int ccount=1;
int w,n;
using namespace std;
vector<pair<int,int> > data;
while(scanf("%d%d",&w,&n)==2 && w!=0)
{
data.assign(n,std::pair<int,int>(0,0));
for(int i=0;i<n;i++)
{
scanf("%d%*[,]%d",&data[i].first ,&data[i].second );
}
Pred pred;
sort(data.begin(),data.end(),pred);
printf("Case %d:",ccount);
#if TEST
for(int i=0;i<n;i++)
{
printf("val=%d,wei=%d\n",data[i].first,data[i].second);
}
#endif
pi result=rec_check(data,0,w);
printf("%d\n%d\n",result.first,result.second);
data.clear();
ccount++;
}
return 0;
}
|
main.c:2:10: fatal error: vector: No such file or directory
2 | #include <vector>
| ^~~~~~~~
compilation terminated.
|
s424372757
|
p00042
|
C
|
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <utility>
#define mp make_pair
#define f first
#define s second
#define dm(x) cerr << #x << " = " << x << endl;
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
typedef pair<int,int> pp;
pp dp[1000][1000];
int p[1001],w[1001];
int W, N;
pp operator+(pp a,pp b)
{
pp ret(a.f+b.f, a.s+b.s);
return ret;
}
//i番目以降でj以下の重さで価値を最大化。 {最大の価値, その時の重さ}
pp calc(int i,int j)
{
pp ret;
if(dp[i][j].f>=0) return dp[i][j];
if(i==N) ret=mp(0,0);
else if(j<w[i]) ret=calc(i+1,j);
else{
pp a=calc(i+1,j);
pp b=calc(i+1,j-w[i]) + mp(p[i],w[i]);
if(a.f>b.f) ret = a;
else if(a.f<b.f) ret = b;
else{
if(a.s > b.s) ret = b;
else ret = a;
}
}
return dp[i][j] = ret;
}
int main()
{
int n=1;
while(scanf("%d", &W),W){
scanf("%d", &N);
rep(i,N) scanf("%d, %d",p+i, w+i);
// rep(i,N) printf("%d: p:%d w:%d\n",i , p[i], w[i]);
rep(i,N+1) rep(j,W+1) {dp[i][j]=mp(-1,-1);}
pp ret=calc(0,W);
// printf(","); rep(j,W+1) printf("%d,",j); printf("\n");
// rep(i,N+1){
// printf("%d,",i);
// rep(j,W+1)
// printf("%d,",calc(i,j).f);
// printf("\n");
// }
// rep(i,N+1){
// printf("%d,",i);
// rep(j,W+1)
// printf("%d,",calc(i,j).s);
// printf("\n");
// }
printf("Case %d:\n%d\n%d\n", n++, ret.f, ret.s);
}
return 0;
}
|
main.c:1:10: fatal error: cstdio: No such file or directory
1 | #include <cstdio>
| ^~~~~~~~
compilation terminated.
|
s018519120
|
p00042
|
C
|
#include<stdio.h>
int num;
int limitWeight;
int value[50],weight[50];
int maxV=0;
void solve(int n,int sumV,int sumW){
if(sumW > limitWeight){
return;
}
else if(n==num){
if(sumV>=maxV){
maxV = sumV;
}
}
else{
flag[n]=1;
solve(n+1,sumV+value[n],sumW+weight[n]);
solve(n+1,sumV,sumW);
}
return;
}
int main(){
int i,j;
while(1){
maxV = 0;
scanf("%d",&limitWeight);
scanf("%d",&num);
if(limitWeight == 0){
break;
}
for(i=0;i<num;i++){
scanf("%d,%d",&value[i],&weight[i]);
}
solve(0,0,0);
printf("%d\n",maxV);
}
}
|
main.c: In function 'solve':
main.c:18:17: error: 'flag' undeclared (first use in this function)
18 | flag[n]=1;
| ^~~~
main.c:18:17: note: each undeclared identifier is reported only once for each function it appears in
|
s351086677
|
p00042
|
C
|
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>
#include<limits.h>
int rec(int, int, int, int *, int *);
int main()
{
int i, W, N, v[1024], w[1024];
while(1){
scanf("%d", &W);
if(W == 0)
break;
memset(v, 0, sizeof(v));
memset(w, 0, sizeof(w));
scanf("%d", &N);
for(i=0; i<N; i++)
scanf("%d,%d", &v[i], &w[i]);
printf("%d\n", rec(0, W, N, v, w));
}
return 0;
}
int rec(int i, int j, int N, int v[], int w[])
{
int res;
if(i == N)
res = 0;
else if(j < w[i])
res = rec(i+1, j, N, v, w);
else{
res = max(rec(i+1, j, N, v, w), rec(i+1, j-w[i], N, v, w) + v[i]);
}
return res;
}
|
main.c: In function 'rec':
main.c:46:23: error: implicit declaration of function 'max'; did you mean 'fmax'? [-Wimplicit-function-declaration]
46 | res = max(rec(i+1, j, N, v, w), rec(i+1, j-w[i], N, v, w) + v[i]);
| ^~~
| fmax
|
s685089664
|
p00042
|
C
|
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>
#include<limits.h>
int min2(int, int);
int dp[1005][10005][2]={0};
int main()
{
int i, j, W, N, v[1024], w[1024], c;
c = 0;
while(1){
scanf("%d", &W);
if(W == 0)
break;
memset(v, 0, sizeof(v));
memset(w, 0, sizeof(w));
memset(dp, 0, sizeof(dp));
scanf("%d", &N);
for(i=0; i<N; i++)
scanf("%d,%d", &v[i], &w[i]);
c++;
printf("Case %d:\n", c);
for(i=0; i<N; i++){
for(j=0; j<=W; j++){
if(j < w[i]){
dp[i+1][j][0] = dp[i][j][0];
dp[i+1][j][1] = dp[i][j][1];
}else{
if(dp[i][j][0] > dp[i][j-w[i]][0] + v[i]){
dp[i+1][j][0] = dp[i][j][0];
dp[i+1][j][1] = dp[i][j][1];
}else if(dp[i][j][0] == dp[i][j-w[i]][0] + v[i]){
dp[i+1][j][0] = dp[i][j][0];
dp[i+1][j][1] = min(dp[i][j][1], dp[i][j-w[i]][1] + w[i]);
}else{
dp[i+1][j][0] = dp[i][j-w[i]][0] + v[i];
dp[i+1][j][1] = dp[i][j-w[i]][1] + w[i];
}
}
}
}
printf("%d\n%d\n", dp[N][W][0], dp[N][W][1]);
}
return 0;
}
int min2(int a, int b){
if(a > b)
return b;
return a;
}
|
main.c: In function 'main':
main.c:49:65: error: implicit declaration of function 'min'; did you mean 'main'? [-Wimplicit-function-declaration]
49 | dp[i+1][j][1] = min(dp[i][j][1], dp[i][j-w[i]][1] + w[i]);
| ^~~
| main
|
s201400986
|
p00042
|
C++
|
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0; i < n;i++)
using namespace std;
int dp[1001][1001];
vector<string> split(const string &str, char delim){
vector<string> res;
size_t current = 0, found;
while((found = str.find_first_of(delim, current)) != string::npos){
res.push_back(string(str, current, found - current));
current = found + 1;
}
res.push_back(string(str, current, str.size() - current));
return res;
}
int main()
{
int count = 0;
int W,n,ans;
int w[1001],v[1001];
while(cin >> W && W)
{
count++;
memset(dp,0,sizeof(dp));
cin >> n;
rep(i,n)
{
string s;
cin >> s;
vector<string> _s = split(s,',');
v[i] = atoi(_s[0].c_str());
w[i] = atoi(_s[1].c_str());
}
for(int i=0;i< n ;i++)
{
for(int j = 0 ; j <= W; j++)
{
if(j < w[i])
{
dp[i+1][j] = dp[i][j];
}
else
{
dp[i+1][j] = max(dp[i][j],dp[i][j - w[i]] + v[i]);
}
}
}
for(int j=0;j <= W ; j++)
{
if(dp[n][j] == dp[n][W])
{
ans = j;
break;
}
}
cout << "Case " << count << endl;
cout << dp[n][W] << endl << ans << endl;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:33:17: error: 'memset' was not declared in this scope
33 | memset(dp,0,sizeof(dp));
| ^~~~~~
a.cc:6:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
5 | #include <algorithm>
+++ |+#include <cstring>
6 |
|
s602271335
|
p00042
|
C++
|
#include<iostream>
#include<algorithm>
int dp[1001][10001];
int v[1001], w[1001];
int main(){
int W;
int k = 1;
while (std::cin >> W, W){
int n;
std::cin >> n;
char a;
for (int i = 0; i < n; i++)std::cin >> v[i] >> a >> w[i];
memset(dp, -1, sizeof(dp));
dp[1][0] = 0;
dp[1][w[0]] = v[0];
for (int i = 1; i < n; i++){
for (int j = 0; j <= W; j++){
if (dp[i][j] != -1){
dp[i + 1][j] = std::max(dp[i + 1][j], dp[i][j]);
if (j + w[i] <= W)dp[i + 1][j + w[i]] = std::max(dp[i + 1][j + w[i]], dp[i][j] + v[i]);
}
}
}
int max = 0, id = 0;
for (int i = 1; i <= W; i++){
if (max < dp[n][i])max = dp[n][i], id = i;
}
std::cout << "Case " << k << ":" << std::endl << max << std::endl << id << std::endl;
k++;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:18:17: error: 'memset' was not declared in this scope
18 | memset(dp, -1, sizeof(dp));
| ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
2 | #include<algorithm>
+++ |+#include <cstring>
3 |
|
s522238140
|
p00042
|
C++
|
x=i=0
while(c=gets.to_i)>0
m=(1..gets.to_i).inject([0]*1e3){|s|v,w=gets.split(?,).map &:to_i;(0..c).map{|j|x=[s[j],w>j ?0:s[j-w]+v].max}}
puts "Case #{i+=1}:",x,m.index(x)
end
|
a.cc:3:4: error: too many decimal points in number
3 | m=(1..gets.to_i).inject([0]*1e3){|s|v,w=gets.split(?,).map &:to_i;(0..c).map{|j|x=[s[j],w>j ?0:s[j-w]+v].max}}
| ^~~~~~~~~~~~
a.cc:3:68: error: too many decimal points in number
3 | m=(1..gets.to_i).inject([0]*1e3){|s|v,w=gets.split(?,).map &:to_i;(0..c).map{|j|x=[s[j],w>j ?0:s[j-w]+v].max}}
| ^~~~
a.cc:1:1: error: 'x' does not name a type
1 | x=i=0
| ^
a.cc:4:1: error: 'puts' does not name a type
4 | puts "Case #{i+=1}:",x,m.index(x)
| ^~~~
|
s824149538
|
p00042
|
C++
|
#include <iostream>
#include <algorithm>
#include <vector>
//#include <stack>
//#include <queue>
//#include <map>
#include <cmath>
//#include <string>
//#include <sstream>
#include <iomanip>
//#include <complex>
#include <stdio.h>
//小数制度 cout << fixed << setprecision(5) << tmp << endl;
using namespace std;
#define ll long long
#define vvi vector< vector<int> >
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
int dp[1010][1010];
int v[1010];
int w[1010];
int main(){
int wei,n;
int cnt = 1;
while(cin >> wei,wei){
cin >> n;
REP(i,1010) REP(j,1010) dp[i][j] = 0;
w[0]=0;v[0]=0;
for(int i=0;i<n;i++){
scanf("%d,%d",&v[i],&w[i]);
}
for(int i=0;i<n;i++){
for(int j=0;j<=awei;j++){
if(j-w[i]<0) dp[i+1][j] = dp[i][j];
else dp[i+1][j]=max(dp[i][j+1],dp[i+1][j-w[i]]+v[i]);
}
}
/*for(int i=0;i<n+1;i++){
for(int j=0;j<wei+1;j++){
cout << dp[i][j] << " ";//l<<endl;
}
cout << endl;
}*/
int maxv=0;
int ans=-1;
for(int i=0;i<wei+1;i++){
if(maxv < dp[n][i]){
maxv = dp[n][i];
ans = i;
}
}
cout << "Case " << cnt << ":" <<endl;
cout << maxv << endl << ans << endl;
cnt++;
}
}
|
a.cc: In function 'int main()':
a.cc:36:22: error: 'awei' was not declared in this scope; did you mean 'wei'?
36 | for(int j=0;j<=awei;j++){
| ^~~~
| wei
|
s215236881
|
p00042
|
C++
|
#include<iostream>
#define MAX_N 1001
#define MAX_W 1001
using namespace std;
int dp[MAX_N][MAX_W];
int n,W;
int w[MAX_N];
int v[MAX_N];
void solve(){
memset(dp,0,sizeof(dp));
cout<<"Case 1:"<<endl;
for(int i=0;i<n;i++){
for(int j=0;j<=W;j++){
if(j>=w[i]){
dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
}else{
dp[i+1][j]=dp[i][j];
}
}
}
cout << dp[n][W] << endl;
int tmp=0;
int weight;
for(int i=0;i<=W;i++){
if(dp[n][i]>tmp){
tmp=dp[n][i];
weight=i;
}
}
cout << weight << endl;
}
int main(){
while(cin>>W,W){
cin>>n;
for(int i=0;i<n;i++){
scanf("%d,%d",&v[i],&w[i]);
}
solve();
}
return 0;
}
|
a.cc: In function 'void solve()':
a.cc:13:3: error: 'memset' was not declared in this scope
13 | memset(dp,0,sizeof(dp));
| ^~~~~~
a.cc:2:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
1 | #include<iostream>
+++ |+#include <cstring>
2 | #define MAX_N 1001
|
s753701363
|
p00042
|
C++
|
#include<iostream>
#include<algorithm>
#define MAX_N 1001
#define MAX_W 1001
using namespace std;
int dp[MAX_N][MAX_W];
int n,W;
int w[MAX_N];
int v[MAX_N];
void solve(){
memset(dp,0,sizeof(dp));
cout<<"Case 1:"<<endl;
for(int i=0;i<n;i++){
for(int j=0;j<=W;j++){
if(j>=w[i]){
dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
}else{
dp[i+1][j]=dp[i][j];
}
}
}
cout << dp[n][W] << endl;
int tmp=0;
int weight;
for(int i=0;i<=W;i++){
if(dp[n][i]>tmp){
tmp=dp[n][i];
weight=i;
}
}
cout << weight << endl;
}
int main(){
while(cin>>W,W){
cin>>n;
for(int i=0;i<n;i++){
scanf("%d,%d",&v[i],&w[i]);
}
solve();
}
return 0;
}
|
a.cc: In function 'void solve()':
a.cc:14:3: error: 'memset' was not declared in this scope
14 | memset(dp,0,sizeof(dp));
| ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
2 | #include<algorithm>
+++ |+#include <cstring>
3 | #define MAX_N 1001
|
s079763298
|
p00042
|
C++
|
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <map>
#define INF 100000000
#define rep(i,a) for(int i=0;i<(a);i++)
using namespace std;
typedef long long ll;
int dp[2000][20000]; //dp[i][j] i番目以前の物で、重さがj以下の時の価値
int W[2000],V[2000];
int w,n;
void solve(){
for(int i=n-1;i>=0;i--){
for(int j=0;j<=w;j++){
if(j-W[i]<0){
dp[i][j]=dp[i+1][j];
}
else{
dp[i][j]=max(dp[i+1][j],dp[i+1][j-W[i]]+V[i]);
}
}
}
cout<<dp[0][w]<<endl;
for(int i=w;i>=1;i--){
if(dp[0][i]!=dp[0][i-1]){
cout<<i<<endl;
break;
}
}
}
int main(){
int count=1;
while(1){
memset(dp,0,sizeof(dp));
cin>>w>>n;
if(w==0)break;
char a;
rep(i,n)cin>>V[i]>>a>>W[i];
cout<<"Case "<<count<<":"<<endl;
count++;
solve();
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:46:9: error: 'memset' was not declared in this scope
46 | memset(dp,0,sizeof(dp));
| ^~~~~~
a.cc:10:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
9 | #include <map>
+++ |+#include <cstring>
10 | #define INF 100000000
|
s777526189
|
p00042
|
C++
|
#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <map>
#define INF 100000000
#define rep(i,a) for(int i=0;i<(a);i++)
using namespace std;
typedef long long ll;
int dp[2000][20000]; //dp[i][j] i番目以前の物で、重さがj以下の時の価値
int W[2000],V[2000];
int w,n;
void solve(){
for(int i=n-1;i>=0;i--){
for(int j=0;j<=w;j++){
if(j-W[i]<0){
dp[i][j]=dp[i+1][j];
}
else{
dp[i][j]=max(dp[i+1][j],dp[i+1][j-W[i]]+V[i]);
}
}
}
cout<<dp[0][w]<<endl;
for(int i=w;i>=1;i--){
if(dp[0][i]!=dp[0][i-1]){
cout<<i<<endl;
break;
}
}
}
int main(){
int count=1;
while(1){
memset(dp,0,sizeof(dp));
cin>>w>>n;
if(w==0)break;
char a;
rep(i,n)cin>>V[i]>>a>>W[i];
cout<<"Case "<<count<<":"<<endl;
count++;
solve();
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:46:9: error: 'memset' was not declared in this scope
46 | memset(dp,0,sizeof(dp));
| ^~~~~~
a.cc:10:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
9 | #include <map>
+++ |+#include <cstring>
10 | #define INF 100000000
|
s173122139
|
p00042
|
C++
|
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <map>
#define INF 100000000
#define rep(i,a) for(int i=0;i<(a);i++)
using namespace std;
typedef long long ll;
short int dp[1001][10001]; //dp[i][j] i番目以前の物で、重さがj以下の時の価値
int W[1001],V[1001];
int w,n;
void solve(){
for(int i=n-1;i>=0;i--){
for(int j=0;j<=w;j++){
if(j-W[i]<0){
dp[i][j]=dp[i+1][j];
}
else{
dp[i][j]=max(dp[i+1][j],dp[i+1][j-W[i]]+V[i]);
}
}
}
cout<<dp[0][w]<<endl;
for(int i=w;i>=1;i--){
if(dp[0][i]!=dp[0][i-1]){
cout<<i<<endl;
break;
}
}
}
int main(){
int count=1;
while(1){
memset(dp,0,sizeof(dp));
cin>>w>>n;
if(w==0)break;
char a;
rep(i,n)cin>>V[i]>>a>>W[i];
cout<<"Case "<<count<<":"<<endl;
count++;
solve();
}
return 0;
}
|
a.cc: In function 'void solve()':
a.cc:29:29: error: no matching function for call to 'max(short int&, int)'
29 | dp[i][j]=max(dp[i+1][j],dp[i+1][j-W[i]]+V[i]);
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
257 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: template argument deduction/substitution failed:
a.cc:29:29: note: deduced conflicting types for parameter 'const _Tp' ('short int' and 'int')
29 | dp[i][j]=max(dp[i+1][j],dp[i+1][j-W[i]]+V[i]);
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
303 | max(const _Tp& __a, const _Tp& __b, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
from a.cc:4:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
5706 | max(initializer_list<_Tp> __l)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
5716 | max(initializer_list<_Tp> __l, _Compare __comp)
| ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: template argument deduction/substitution failed:
a.cc:29:29: note: mismatched types 'std::initializer_list<_Tp>' and 'short int'
29 | dp[i][j]=max(dp[i+1][j],dp[i+1][j-W[i]]+V[i]);
| ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
s524937782
|
p00042
|
C++
|
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
int max(int a,int b){
if(a>=b)return a;
else return b;
}
int min(int a,int b){
if(a>=b)return b;
else return a;
}
void swap(int *a,int *b){
int tmp = *a;
*a = *b;
*b = tmp;
}
void babbleSort(int *data,int n){
for(int i=0;i<n;i++){
for(int j=n-1;j>i;j--){
if(data[j]>=data[j-1]){
swap(&data[j],&data[j-1]);
}
}
}
}
using namespace std;
/*
cin.ignore();
getline(cin,dataStr);
data = new int[n];
stringToInteger(&dataStr,data,n);
*/
void stringToInteger(string *str,int *data,int n){
for(int i=1;i<=n;i++){
int spaceN = str->find(' ',0);
data[i] = atoi(str->substr(0,spaceN).c_str());
str->erase(0,spaceN+1);
}
}
int dp[1010];
//dp[i] i:重さ
int main(){
int w,n;
int cnt=1;
while(1){
cin>>w;
if(w==0)break;
cin>>n;
for(int i=0;i<=w;i++){
dp[i]=0;
}
int value,weight;
for(int i=0;i<n;i++){
scanf("%d,%d",&value,&weight);
for(int j=w;j>=0;j--){
if((j==0||dp[j]>0)&&((j+weight)<=w)){
int tmp = dp[j]+value;
dp[j+weight] = max(tmp,dp[j+weight]);
// cout<<j+weight<<" "<<dp[j+weight]<<endl;
}
}
}
int ans=0;
int ansCnt=0;
for(int i=0;i<=w;i++){
if(ans<dp[i]){
ans=dp[i];
ansCnt=i;
}
}
cout<<Case<<" "<<cnt<<":"<<endl;
cout<<ans<<endl;
cout<<ansCnt<<endl;
cnt++;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:98:23: error: 'Case' was not declared in this scope
98 | cout<<Case<<" "<<cnt<<":"<<endl;
| ^~~~
|
s319754864
|
p00042
|
C++
|
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define MAX_N 1000
#define MAX_W 1000
int N, W;
int v[MAX_N], w[MAX_N];
int memo[MAX_N][MAX_W];
int resW = 1e9;
int solve(int index, int weight){
if(memo[index][weight] > 0) return memo[index][weight];
int res;
if(index == N) res = 0;
else if(weight < w[index]) res = solve(index + 1, weight);
else{
res = max(solve(index + 1, weight), solve(index + 1, weight - w[index]) + v[index]);
}
return memo[index][weight] = res;
}
void askw(int ans, int weight, int index){
if(ans == 0){
if(weight < resW) resW = weight;
}
if(index == N) return;
if(ans - v[index] >= 0){
askw(ans - v[index], weight + w[index], index + 1);
askw(ans, weight, index + 1);
}
}
int main(void){
int cnt = 0, ans;
while(cin >> W, W){
cnt++;
cin >> N;
for(int i = 0; i < N; i++){
scanf("%d,%d", &v[i], &w[i]);
}
memset(memo, -1, sizeof(memo));
ans = solve(0, W); askw(ans, 0, 0);
cout << "Case " << cnt << ":" << endl;
cout << ans << endl;
cout << resW << endl;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:44:5: error: 'memset' was not declared in this scope
44 | memset(memo, -1, sizeof(memo));
| ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
3 | #include <algorithm>
+++ |+#include <cstring>
4 | using namespace std;
|
s919877224
|
p00042
|
C++
|
Case 1:
220
49
Case 2:
220
49
|
a.cc:1:1: error: 'Case' does not name a type
1 | Case 1:
| ^~~~
|
s909256814
|
p00042
|
C++
|
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int w[1000],v[1000];
int W,N;
int memo[1001][1001];
int func(int i,j){
if(memo[i][j]>=0)return memo[i][j];
int res;
if(i==N)res=0;
else if(j-w[i]<0)res=func(i+1,j);
else res=max(func(i+1,j),func(i+1,j-w[i])+v[i]);
return memo[i][j]=res;
}
int main(){
int cnt=0;
while(cin>>W,W){
cin>>N;
cnt++;
for(int i=0;i<N;i++)(cin>>v[i]).ignore()>>w[i];
fill(memo[0],memo[0]+1001*1001,-1);
memo[0][0]=0;
func(0,W);
for(int i=W;i>=0;i--){
if(memo[0][i]==-1)continue;
if(memo[0][i]>memo[0][i-1]){
cout<<"Case "<<cnt<<":"<<endl;
cout<<memo[0][i]<<endl<<i<<endl;
break;
}
}
}
return 0;
}
|
a.cc:8:16: error: 'j' has not been declared
8 | int func(int i,j){
| ^
a.cc: In function 'int func(int, int)':
a.cc:9:16: error: 'j' was not declared in this scope
9 | if(memo[i][j]>=0)return memo[i][j];
| ^
a.cc:13:13: error: 'j' was not declared in this scope
13 | else if(j-w[i]<0)res=func(i+1,j);
| ^
a.cc:16:20: error: 'j' was not declared in this scope
16 | return memo[i][j]=res;
| ^
|
s787781111
|
p00042
|
C++
|
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){
int w,n,cnt=1;
int dp[1006][10005],V[1001],W[1001];
while(cin>>w,w){
cin>>n;
for(int i=0;i<n;i++)scanf("%d,%d",&V[i],&W[i]);
int cnt=0;for(int i=0;i<n;i++)cnt+=W[i];
if(cnt>=10000)for(;;);
for(int i=1;i<=n;i++){
for(int j=0;j<=w;j++){
if(j-W[i-1]>=0)dp[i][j]=max(dp[i-1][j],dp[i-1][j-W[i-1]]+V[i-1]);
if(dp[i
}
}
int tmp=w;
for(int i=w;i>=0;i--)if(dp[n][i]==dp[n][w])tmp=i;
cout<<"Case "<<cnt<<":"<<endl<<dp[n][w]<<endl<<tmp<<endl;
cnt++;
for(int i=0;i<1001;i++)for(int j=0;j<=1000;j++)V[i]=W[i]=0;
for(int i=0;i<1006;i++)fill(dp[i],dp[i+10005],0);
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:17:40: error: expected ']' before '}' token
17 | if(dp[i
| ^
| ]
18 | }
| ~
a.cc:17:40: error: expected ')' before '}' token
17 | if(dp[i
| ~ ^
| )
18 | }
| ~
a.cc:18:25: error: expected primary-expression before '}' token
18 | }
| ^
|
s836264701
|
p00042
|
C++
|
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){
int w,n,cnt=1;
int dp[1006][10005],V[1001],W[1001];
while(cin>>w,w){
cin>>n;
for(int i=0;i<n;i++)scanf("%d,%d",&V[i],&W[i]);
int cnt=0;for(int i=0;i<n;i++)cnt+=W[i];
if(cnt>=10000)for(;;);
for(int i=1;i<=n;i++){
for(int j=0;j<=w;j++){
if(j-W[i-1]>=0)dp[i][j]=max(dp[i-1][j],dp[i-1][j-W[i-1]]+V[i-1]);
if(dp[i
}
}
int tmp=w;
for(int i=w;i>=0;i--)if(dp[n][i]==dp[n][w])tmp=i;
cout<<"Case "<<cnt<<":"<<endl<<dp[n][w]<<endl<<tmp<<endl;
cnt++;
for(int i=0;i<1001;i++)for(int j=0;j<=1000;j++)V[i]=W[i]=0;
for(int i=0;i<1006;i++)fill(dp[i],dp[i]+10005,0);
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:17:40: error: expected ']' before '}' token
17 | if(dp[i
| ^
| ]
18 | }
| ~
a.cc:17:40: error: expected ')' before '}' token
17 | if(dp[i
| ~ ^
| )
18 | }
| ~
a.cc:18:25: error: expected primary-expression before '}' token
18 | }
| ^
|
s921425649
|
p00042
|
C++
|
#include<iostream>
using namespace std;
int main(){
int dp[1001][1001];
int n,W;
int v[1000],w[1000];
int num=0;
while(cin>> W,W){
num++;
cin>> n;
for(int i=0;i<w+1;i++){
dp[0][i]=0;
}
for(int i=0;i<n;i++){
char c;
cin>> v[i]>> c>> w[i];
}
for(int i=1;i<=n;i++){
for(int j=1;j<=W;j++){
if(j<w[i-1]){
dp[i][j]=dp[i-1][j];
}else{
dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
}
}
}
int mv=0,mw;
for(int j=0;j<=W;j++){
if(mv<dp[n][j]){
mv=dp[n][j];
mw=j;
}
}
/*for(int i=0;i<=n;i++){
for(int j=0;j<=W;j++){
cout<< dp[i][j];
}
cout<< endl<< endl;
}
*/
cout<< "Case "<< num<< ":"<< endl;
cout<< mv<< endl;
cout<< mw<< endl;
}
}
|
a.cc: In function 'int main()':
a.cc:11:18: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
11 | for(int i=0;i<w+1;i++){
| ~^~~~
|
s712543533
|
p00042
|
C++
|
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int w,n;
int kati[1111],omo[1111];
int memo[1111][1111];
int main(){
int cas=0;
int anskati=0;
int ansomo;
int w,n;
int kati[1111],omo[1111];
int memo[1111][1111];
while(1){
cas++;
cin>>w;
if(w==0) break;
cin>>n;
for(int i=0;i<=W;i++){
memo[0][i]=0;
}
for(int i=0;i<n;i++){
scanf("%d,%d",&kati[i],&omo[i]);
}
cout<<"Case "<<cas<<':'<<endl;
for(int i=1;i<=n;i++){
for(int j=1;j<=w;j++){
if(j<omo[i-1]){
memo[i][j]=memo[i-1][j];
}else{
memo[i][j]=max(memo[i-1][j],memo[i-1][j-omo[i-1]]+kati[i-1]);
}
}
}
for(int i=0;i<=w;i++){
if(memo[n][i]>anskati){
anskati=memo[n][i];
ansomo=i;
}
}
cout<<anskati<<endl;
cout<<ansomo<<endl;
}
}
|
a.cc: In function 'int main()':
a.cc:20:20: error: 'W' was not declared in this scope
20 | for(int i=0;i<=W;i++){
| ^
|
s359049925
|
p00042
|
C++
|
#include <iostream>
#include <cstdio>
using namespace std;
ll value[1000], weight[1000];
ll dp[1001][1001]; // dp[?¬?????????????][??????] = ?????§??????
int main() {
int W;
int c = 1;
while ( cin >> W, W ) {
int N; cin >> N;
for (int i = 0; i < N; ++i) scanf("%d,%d", &value[i], &weight[i]);
fill(&dp[0][0], &dp[0][0]+1001*1001, 0);
for (int i = 0; i < N; ++i) {
for (int w = 0; w <= W; ++w) {
dp[i+1][w] = max(dp[i+1][w], dp[i][w]);
if (w + weight[i] <= W) {
dp[i+1][w+weight[i]] = max(dp[i+1][w+weight[i]], dp[i][w]+value[i]);
}
}
}
ll av = 0, aw = 0;
for (int w = 0; w < W; ++w) {
if (dp[N][w] > av) {
av = dp[N][w];
aw = w;
}
}
printf("Case %d:\n", c++);
printf("%d\n", av);
printf("%d\n", aw);
}
}
|
a.cc:6:1: error: 'll' does not name a type
6 | ll value[1000], weight[1000];
| ^~
a.cc:7:1: error: 'll' does not name a type
7 | ll dp[1001][1001]; // dp[?¬?????????????][??????] = ?????§??????
| ^~
a.cc: In function 'int main()':
a.cc:14:61: error: 'value' was not declared in this scope
14 | for (int i = 0; i < N; ++i) scanf("%d,%d", &value[i], &weight[i]);
| ^~~~~
a.cc:14:72: error: 'weight' was not declared in this scope
14 | for (int i = 0; i < N; ++i) scanf("%d,%d", &value[i], &weight[i]);
| ^~~~~~
a.cc:16:23: error: 'dp' was not declared in this scope
16 | fill(&dp[0][0], &dp[0][0]+1001*1001, 0);
| ^~
a.cc:21:41: error: 'weight' was not declared in this scope
21 | if (w + weight[i] <= W) {
| ^~~~~~
a.cc:22:99: error: 'value' was not declared in this scope
22 | dp[i+1][w+weight[i]] = max(dp[i+1][w+weight[i]], dp[i][w]+value[i]);
| ^~~~~
a.cc:26:17: error: 'll' was not declared in this scope
26 | ll av = 0, aw = 0;
| ^~
a.cc:28:40: error: 'av' was not declared in this scope
28 | if (dp[N][w] > av) {
| ^~
a.cc:30:33: error: 'aw' was not declared in this scope; did you mean 'w'?
30 | aw = w;
| ^~
| w
a.cc:34:32: error: 'av' was not declared in this scope
34 | printf("%d\n", av);
| ^~
a.cc:35:32: error: 'aw' was not declared in this scope
35 | printf("%d\n", aw);
| ^~
|
s217424348
|
p00042
|
C++
|
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
using namespace std;
struct Treasure{
int Weight;
int Worth;
};
vector<int> TempMaxWorth;
int GetMaxWorth(const int MaxWeight,vector<Treasure> nowTreasureCollection,vector<Treasure>::iterator& nowIterator,const vector<Treasure>& AllTreasureCollection){
vector<Treasure>::iterator rootIterator(nowIterator);
for (; nowIterator!=AllTreasureCollection.end(); ++nowIterator){
nowTreasureCollection.push_back(*(nowIterator));
const int NowWorth = accumulate(nowTreasureCollection.cbegin(),
nowTreasureCollection.cend(),
0,
[](const int q, const Treasure& p){return q + p.Worth; }
);
const int NowWeight = accumulate(nowTreasureCollection.cbegin(),
nowTreasureCollection.cend(),
0,
[](const int q, const Treasure& p){return q + p.Weight; });
if (NowWeight <= MaxWeight&&NowWorth > TempMaxWorth[NowWeight]){
TempMaxWorth[NowWeight] = NowWorth;
replace_if(TempMaxWorth.begin() + NowWeight, TempMaxWorth.end(), [=](int n){return NowWorth > n; }, NowWorth);
if((++nowIterator)!=AllTreasureCollection.end())GetMaxWorth(MaxWeight, nowTreasureCollection, nowIterator,AllTreasureCollection);
nowIterator--;
}
nowTreasureCollection.pop_back();
}
((nowIterator)) = (rootIterator);
return 0;
}
int main(){
int MaxWeight;
int TreasureNum;
for (int i = 1; cin >> MaxWeight;++i){
if (MaxWeight == 0)return 0;
cin >> TreasureNum;
TempMaxWorth.resize(MaxWeight + 1);
fill(TempMaxWorth.begin(), TempMaxWorth.end(), 0);
vector<Treasure> AllTreasureCollection;
for (int j = 0; j < TreasureNum; ++j){
Treasure T;
cin >> T.Worth;
cin.get();
cin >> T.Weight;
AllTreasureCollection.push_back(T);
}
vector<Treasure> NowTreasureCollection = {};
GetMaxWorth(MaxWeight, NowTreasureCollection, AllTreasureCollection.begin(), AllTreasureCollection);
cout << "Case " << i << " :" << endl << TempMaxWorth[MaxWeight] << endl << find(TempMaxWorth.cbegin(), TempMaxWorth.cend(), TempMaxWorth[MaxWeight]) - TempMaxWorth.cbegin() << endl;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:56:90: error: cannot bind non-const lvalue reference of type 'std::vector<Treasure>::iterator&' to an rvalue of type 'std::vector<Treasure>::iterator'
56 | GetMaxWorth(MaxWeight, NowTreasureCollection, AllTreasureCollection.begin(), AllTreasureCollection);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
a.cc:14:104: note: initializing argument 3 of 'int GetMaxWorth(int, std::vector<Treasure>, std::vector<Treasure>::iterator&, const std::vector<Treasure>&)'
14 | int GetMaxWorth(const int MaxWeight,vector<Treasure> nowTreasureCollection,vector<Treasure>::iterator& nowIterator,const vector<Treasure>& AllTreasureCollection){
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
|
s972893184
|
p00042
|
C++
|
#include <cstdio>
using namespace std;
struct pre{ int v, w; };
int max(int a, int b){
return (a > b) a : b;
}
int main(){
const int MAX_N = 1000, MAX_W = 1000;
int N, W;
pre dat[MAX_N];
int dp[MAX_N][MAX_W + 1];
int p;
for(int n = 1;; n++){
scanf("%d", &W);
if(W == 0) break;
scanf("%d", &N);
for(int i = 0; i < N; i++) scanf("%d,%d", &dat[i].v, &dat[i].w);
for(int i = 0; i < MAX_N; i++){
for(int j = 0; j < MAX_W; j++){
dp[i][j] = 0;
}
}
for(int i = dat[0].w; i <= W; i++) dp[0][i] = dat[0].v;
for(int i = 1; i < N; i++){
for(int j = 0; j <= W; j++){
dp[i][j] = max((dat[i].w <= j)? dp[i - 1][j - dat[i].w] + dat[i].v : 0, dp[i - 1][j]);
}
}
for(int i = 0; i <= W; i++){
if(dp[N - 1][i] == dp[N - 1][W]){
printf("Case %d:\n%d\n%d\n", n, dp[N - 1][W], i);
break;
}
}
}
return 0;
}
|
a.cc: In function 'int max(int, int)':
a.cc:7:23: error: expected ';' before 'a'
7 | return (a > b) a : b;
| ^~
| ;
|
s655578622
|
p00042
|
C++
|
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;
#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int dp[1500][1500];
int solve(int i,int j){
if(dp[i][j] != -1) return dp[i][j];
int hoge;
if(i == n) hoge = 0;
else if(j < w[i]) hoge = solve(i+1, j);
else hoge = max(solve(i+1, j) , solve(i+1 , j - w[i]) + v[i]);
return dp[i][j] = hoge;
}
int main(){
while(1){
int h;
cin >> h;
if(h == 0) break;
int n;
cin >> n;
int v[1500],w[1500];
REP(i,n){
cin >> v[i]>> w[i];
}
REP(i,1500) REP(j,1500) dp[i][j] = -1;
cout << solve(0,h) << endl;
}
}
|
a.cc: In function 'int solve(int, int)':
a.cc:35:11: error: 'n' was not declared in this scope
35 | if(i == n) hoge = 0;
| ^
a.cc:37:15: error: 'w' was not declared in this scope
37 | else if(j < w[i]) hoge = solve(i+1, j);
| ^
a.cc:39:60: error: 'v' was not declared in this scope
39 | else hoge = max(solve(i+1, j) , solve(i+1 , j - w[i]) + v[i]);
| ^
|
s429450751
|
p00042
|
C++
|
#include<iostream>
#include<vector>
using namespace std;
int main(){
int w,n,va,we;
int dp[1000];
char c;
vector<pair<int,int> >vec;
while(cin>>w>>n,w){
for(int i=0;i<n;i++){
cin>>va>>c>>we;
vec.push_back(make_pair(va, we));
}
memset(dp,0,sizeof(dp));
for(int i=0;i<n;i++){
int tv=vec[i].first, tw=vec[i].second;
for(int j=w;j>=0;j--){
if(tw==j)continue;
if(tw+j<=w){
dp[tw+j]=max(dp[tw+j],dp[j]+tv);
}
}
}
int aw=0,av=0;
for(int i=0;i<=w;i++) {
if(dp[i]>av){
aw=i;
av=dp[i];
}
}
cout<<av<<endl<<aw<<endl;
vec.clear();
}
}
|
a.cc: In function 'int main()':
a.cc:16:9: error: 'memset' was not declared in this scope
16 | memset(dp,0,sizeof(dp));
| ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
2 | #include<vector>
+++ |+#include <cstring>
3 | using namespace std;
|
s563831805
|
p00042
|
C++
|
#include <iostream>
#include <cstdio>
#include <algorithm>
#define MAX_N 1001
#define MAX_W 10001
int dp[MAX_W][MAX_N], W, N, value[MAX_N], w[MAX_N];
int main(){
int Case = 0;
while(true){
for(int i = 0; i < MAX_N; ++i)
memset(dp[i], 0, MAX_W);
//initialize
++Case;
scanf("%d%d", &W, &N);
if(!W)
break;
for(int i = 0; i < N; ++i)
scanf("%d,%d", &value[i], &w[i]);
//input
for(int i = 0; i < N; ++i){
for(int j = 0; j <= W; ++j){
if(j < w[i])
dp[i + 1][j] = dp[i][j];
else
dp[i + 1][j] = std::max(dp[i][j - w[i]] + value[i], dp[i][j]);
}
}
//solve
int ans = dp[N][W];
printf("Case %d:\n%d\n", Case, ans);
int i = 0;
while(true){
if(ans != dp[N][W - i]){
printf("%d\n", W - i + 1);
break;
}
++i;
}
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:15:13: error: 'memset' was not declared in this scope
15 | memset(dp[i], 0, MAX_W);
| ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
3 | #include <algorithm>
+++ |+#include <cstring>
4 |
|
s469336540
|
p00042
|
C++
|
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
typedef pair<int,int> P;
int main(){
int W,N,cou=0;
int tr[1001],we[1001];
while(cin >> W , W){
cou++;
cin >> N;
for(int i=1;i<=N;i++){
scanf("%d,%d",&tr[i],&we[i]);
}
P dp[1010][1001];
for(int i=0;i<=N;i++){
for(int j=0;j<=N;j++){
dp[i][j] = P(0,0);
}
}
dp[0][0] = P(0,0);
for(int i=1;i<=N;i++){
dp[i][0] = P(0,0);
for(int j=0;j<i;j++){
if(dp[i-1][j].second+we[i] <= W){
P p;
p = P(dp[i-1][j].first+tr[i],dp[i-1][j].second+we[i]);
if(p.first == dp[i-1][j+1].first){
if(p.second < dp[i-1][j+1].second) dp[i][j+1] = p;
else dp[i][j+1] = dp[i-1][j+1];
}
else if(p.first > dp[i-1][j+1].first){
dp[i][j+1] = p;
}
else dp[i][j+1] = dp[i-1][j+1];
}
else dp[i][j+1] = dp[i-1][j+1];
}
}
int ans1=0,ans2=0;
for(int i=0;i<=N;i++){
if(dp[N][i].first == ans1){
if(dp[N][i].second < ans2) ans2 = dp[N][i].second;
}
else if(dp[N][i].first > ans1){
ans1 = dp[N][i].first;
ans2 = dp[N][i].second;
}
}
cout << "Case " << cou << ":" << endl;
cout << ans1 << endl;
cout << ans2 << endl;
}
|
a.cc: In function 'int main()':
a.cc:57:10: error: expected '}' at end of input
57 | }
| ^
a.cc:8:11: note: to match this '{'
8 | int main(){
| ^
|
s351823540
|
p00042
|
C++
|
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define READ_BY_TEXT false
vector<string> splitByDelimiter(string target, string delim) {
std::string s = target;
std::string delimiter = delim;
size_t pos = 0;
std::string token;
vector<string> arr;
while ((pos = s.find(delimiter)) != std::string::npos) {
token = s.substr(0, pos);
arr.push_back(token);
s.erase(0, pos + delimiter.length());
}
arr.push_back(s);
return arr;
}
int W, N;
int w[1000], v[1000];
int dp[1000][1000];
//vector<int> lines;
//int max_v, min_w;
int recursive(int i, int j) {
if (dp[i][j] != -1) return dp[i][j];
int ret;
if (i >= N) {
ret = 0;
}
else if (j < w[i]) {
ret = recursive(i+1, j);
}
else {
ret = max(recursive(i+1, j), recursive(i+1, j-w[i])+v[i]);
}
dp[i][j] = ret;
return ret;
}
int calcMinWeight(int i, int j) {
if (i >= N) {
return 0;
}
int m_w = W;
if (dp[i][j] == -1) {
m_w = min(m_w, calcMinWeight(i+1, j));
}
else {
m_w = min(m_w, calcMinWeight(i+1, j-w[i]) + w[i]);
}
return m_w;
}
int main() {
#if READ_BY_TEXT
// Get values from test.txt
std::ifstream ifs("test.txt");
std::string str;
if (ifs.fail())
{
std::cerr << "??±???" << std::endl;
return -1;
}
getline(ifs, str);
vector<string> words = splitByDelimiter(str, " ");
num_d = stoi(words[0]);
num_n = stoi(words[1]);
for (int i=0; i<num_n; i++) {
getline(ifs, str);
lines.push_back(stoi(str));
}
#else
int case_v = 1;
while (true) {
cin >> W;
if (!W) break;
cin >> N;
string input;
for (int i = 0; i < N; i++) {
// getline(cin, input);
cin >> input;
vector<string> words = splitByDelimiter(input, ",");
v[i] = stoi(words[0]);
w[i] = stoi(words[1]);
}
memset(dp, -1, sizeof(dp));
// Solve
int min_w = W;
int max_v = recursive(0, W);
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
// cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl;
if (dp[i][j] == max_v) {
// cout << "i " << i << " j " << j << endl;
min_w = min(min_w, calcMinWeight(i, j));
// min_w = min(j, min_w);
}
}
}
cout << "Case " << case_v << ":" << endl;
cout << max_v << endl;
cout << min_w << endl;
case_v++;
}
// string input;
// getline(cin, input);
// vector<string> words = splitByDelimiter(input, " ");
// num_d = stoi(words[0]);
// num_n = stoi(words[1]);
// string input1;
// for (int i=0; i<num_n; i++) {
// getline(cin, input1);
// lines.push_back(stoi(input1));
// }
#endif
// recursive(0, 0, "");
// cout << result << endl;
// cout << "num_d = " << num_d << " num_n = " << num_n << "\n";
//
// // Check parsed contents
// for (int i = 0; i < lines.size(); i++) {
// cout << "line[" << i << "] " << to_string(lines[i]) << "\n";
// }
return 0;
}
|
a.cc: In function 'int main()':
a.cc:100:9: error: 'memset' was not declared in this scope
100 | memset(dp, -1, sizeof(dp));
| ^~~~~~
a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
4 | #include <vector>
+++ |+#include <cstring>
5 | using namespace std;
|
s844670166
|
p00042
|
C++
|
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define READ_BY_TEXT false
vector<string> splitByDelimiter(string target, string delim) {
std::string s = target;
std::string delimiter = delim;
size_t pos = 0;
std::string token;
vector<string> arr;
while ((pos = s.find(delimiter)) != std::string::npos) {
token = s.substr(0, pos);
arr.push_back(token);
s.erase(0, pos + delimiter.length());
}
arr.push_back(s);
return arr;
}
int W, N;
int w[1000], v[1000];
int dp[1000][1000];
//vector<int> lines;
//int max_v, min_w;
int recursive(int i, int j) {
if (dp[i][j] != -1) return dp[i][j];
int ret;
if (i >= N) {
ret = 0;
}
else if (j < w[i]) {
ret = recursive(i+1, j);
}
else {
ret = max(recursive(i+1, j), recursive(i+1, j-w[i])+v[i]);
}
dp[i][j] = ret;
return ret;
}
int calcMinWeight(int i, int j) {
if (i >= N) {
return 0;
}
int m_w = W;
if (dp[i][j] == -1) {
m_w = min(m_w, calcMinWeight(i+1, j));
}
else {
m_w = min(m_w, calcMinWeight(i+1, j-w[i]) + w[i]);
}
return m_w;
}
int main() {
#if READ_BY_TEXT
// Get values from test.txt
std::ifstream ifs("test.txt");
std::string str;
if (ifs.fail())
{
std::cerr << "??±???" << std::endl;
return -1;
}
getline(ifs, str);
vector<string> words = splitByDelimiter(str, " ");
num_d = stoi(words[0]);
num_n = stoi(words[1]);
for (int i=0; i<num_n; i++) {
getline(ifs, str);
lines.push_back(stoi(str));
}
#else
int case_v = 1;
while (true) {
cin >> W;
if (!W) break;
cin >> N;
string input;
for (int i = 0; i < N; i++) {
// getline(cin, input);
cin >> input;
vector<string> words = splitByDelimiter(input, ",");
v[i] = stoi(words[0]);
w[i] = stoi(words[1]);
}
memset(dp, -1, sizeof(dp));
// Solve
int min_w = W;
int max_v = recursive(0, W);
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
// cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl;
if (dp[i][j] == max_v) {
// cout << "i " << i << " j " << j << endl;
min_w = min(min_w, calcMinWeight(i, j));
// min_w = min(j, min_w);
}
}
}
cout << "Case " << case_v << ":" << endl;
cout << max_v << endl;
cout << min_w << endl;
case_v++;
}
// string input;
// getline(cin, input);
// vector<string> words = splitByDelimiter(input, " ");
// num_d = stoi(words[0]);
// num_n = stoi(words[1]);
// string input1;
// for (int i=0; i<num_n; i++) {
// getline(cin, input1);
// lines.push_back(stoi(input1));
// }
#endif
// recursive(0, 0, "");
// cout << result << endl;
// cout << "num_d = " << num_d << " num_n = " << num_n << "\n";
//
// // Check parsed contents
// for (int i = 0; i < lines.size(); i++) {
// cout << "line[" << i << "] " << to_string(lines[i]) << "\n";
// }
return 0;
}
|
a.cc: In function 'int main()':
a.cc:100:9: error: 'memset' was not declared in this scope
100 | memset(dp, -1, sizeof(dp));
| ^~~~~~
a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
4 | #include <vector>
+++ |+#include <cstring>
5 | using namespace std;
|
s799904456
|
p00042
|
C++
|
//
// others.cpp
// sample
//
// Created by MIO-MACMINI on 2015/09/01.
// Copyright (c) 2015??´ MIO-MACMINI. All rights reserved.
//
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define READ_BY_TEXT false
vector<string> splitByDelimiter(string target, string delim) {
std::string s = target;
std::string delimiter = delim;
size_t pos = 0;
std::string token;
vector<string> arr;
while ((pos = s.find(delimiter)) != std::string::npos) {
token = s.substr(0, pos);
arr.push_back(token);
s.erase(0, pos + delimiter.length());
}
arr.push_back(s);
return arr;
}
int W, N;
int w[1000], v[1000];
int dp[1000][1000];
//vector<int> lines;
//int max_v, min_w;
int recursive(int i, int j) {
if (dp[i][j] != -1) return dp[i][j];
int ret;
if (i >= N) {
ret = 0;
}
else if (j < w[i]) {
ret = recursive(i+1, j);
}
else {
ret = max(recursive(i+1, j), recursive(i+1, j-w[i])+v[i]);
}
dp[i][j] = ret;
return ret;
}
int calcMinWeight(int i, int j) {
if (i >= N) {
return 0;
}
int m_w = W;
if (dp[i][j] == -1) {
m_w = min(m_w, calcMinWeight(i+1, j));
}
else {
m_w = min(m_w, calcMinWeight(i+1, j-w[i]) + w[i]);
}
return m_w;
}
int main() {
#if READ_BY_TEXT
// Get values from test.txt
std::ifstream ifs("test.txt");
std::string str;
if (ifs.fail())
{
std::cerr << "??±???" << std::endl;
return -1;
}
getline(ifs, str);
vector<string> words = splitByDelimiter(str, " ");
num_d = stoi(words[0]);
num_n = stoi(words[1]);
for (int i=0; i<num_n; i++) {
getline(ifs, str);
lines.push_back(stoi(str));
}
#else
int case_v = 1;
while (true) {
cin >> W;
if (!W) break;
cin >> N;
string input;
for (int i = 0; i < N; i++) {
// getline(cin, input);
cin >> input;
vector<string> words = splitByDelimiter(input, ",");
v[i] = stoi(words[0]);
w[i] = stoi(words[1]);
}
memset(dp, -1, sizeof(dp));
// Solve
int min_w = W;
int max_v = recursive(0, W);
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
// cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl;
if (dp[i][j] == max_v) {
// cout << "i " << i << " j " << j << endl;
min_w = min(min_w, calcMinWeight(i, j));
// min_w = min(j, min_w);
}
}
}
cout << "Case " << case_v << ":" << endl;
cout << max_v << endl;
cout << min_w << endl;
case_v++;
}
// string input;
// getline(cin, input);
// vector<string> words = splitByDelimiter(input, " ");
// num_d = stoi(words[0]);
// num_n = stoi(words[1]);
// string input1;
// for (int i=0; i<num_n; i++) {
// getline(cin, input1);
// lines.push_back(stoi(input1));
// }
#endif
// recursive(0, 0, "");
// cout << result << endl;
// cout << "num_d = " << num_d << " num_n = " << num_n << "\n";
//
// // Check parsed contents
// for (int i = 0; i < lines.size(); i++) {
// cout << "line[" << i << "] " << to_string(lines[i]) << "\n";
// }
return 0;
}
|
a.cc: In function 'int main()':
a.cc:108:9: error: 'memset' was not declared in this scope
108 | memset(dp, -1, sizeof(dp));
| ^~~~~~
a.cc:13:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
12 | #include <vector>
+++ |+#include <cstring>
13 | using namespace std;
|
s746921397
|
p00042
|
C++
|
#include <fstream>
#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
using namespace std;
#define READ_BY_TEXT false
vector<string> splitByDelimiter(string target, string delim) {
std::string s = target;
std::string delimiter = delim;
size_t pos = 0;
std::string token;
vector<string> arr;
while ((pos = s.find(delimiter)) != std::string::npos) {
token = s.substr(0, pos);
arr.push_back(token);
s.erase(0, pos + delimiter.length());
}
arr.push_back(s);
return arr;
}
int W, N;
int w[1000], v[1000];
int dp[1000][1000];
//vector<int> lines;
//int max_v, min_w;
int recursive(int i, int j) {
if (dp[i][j] != -1) return dp[i][j];
int ret;
if (i >= N) {
ret = 0;
}
else if (j < w[i]) {
ret = recursive(i+1, j);
}
else {
ret = max(recursive(i+1, j), recursive(i+1, j-w[i])+v[i]);
}
dp[i][j] = ret;
return ret;
}
int calcMinWeight(int i, int j) {
if (i >= N) {
return 0;
}
int m_w = W;
if (dp[i][j] == -1) {
m_w = min(m_w, calcMinWeight(i+1, j));
}
else {
m_w = min(m_w, calcMinWeight(i+1, j-w[i]) + w[i]);
}
return m_w;
}
int main() {
#if READ_BY_TEXT
// Get values from test.txt
std::ifstream ifs("test.txt");
std::string str;
if (ifs.fail())
{
std::cerr << "??±???" << std::endl;
return -1;
}
getline(ifs, str);
vector<string> words = splitByDelimiter(str, " ");
num_d = stoi(words[0]);
num_n = stoi(words[1]);
for (int i=0; i<num_n; i++) {
getline(ifs, str);
lines.push_back(stoi(str));
}
#else
int case_v = 1;
while (true) {
cin >> W;
if (!W) break;
cin >> N;
string input;
for (int i = 0; i < N; i++) {
// getline(cin, input);
cin >> input;
vector<string> words = splitByDelimiter(input, ",");
v[i] = stoi(words[0]);
w[i] = stoi(words[1]);
}
memset(dp, -1, sizeof(dp));
// Solve
int min_w = W;
int max_v = recursive(0, W);
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
// cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl;
if (dp[i][j] == max_v) {
// cout << "i " << i << " j " << j << endl;
min_w = min(min_w, calcMinWeight(i, j));
// min_w = min(j, min_w);
}
}
}
cout << "Case " << case_v << ":" << endl;
cout << max_v << endl;
cout << min_w << endl;
case_v++;
}
// string input;
// getline(cin, input);
// vector<string> words = splitByDelimiter(input, " ");
// num_d = stoi(words[0]);
// num_n = stoi(words[1]);
// string input1;
// for (int i=0; i<num_n; i++) {
// getline(cin, input1);
// lines.push_back(stoi(input1));
// }
#endif
// recursive(0, 0, "");
// cout << result << endl;
// cout << "num_d = " << num_d << " num_n = " << num_n << "\n";
//
// // Check parsed contents
// for (int i = 0; i < lines.size(); i++) {
// cout << "line[" << i << "] " << to_string(lines[i]) << "\n";
// }
return 0;
}
|
a.cc: In function 'int main()':
a.cc:101:9: error: 'memset' was not declared in this scope
101 | memset(dp, -1, sizeof(dp));
| ^~~~~~
a.cc:6:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
5 | #include <vector>
+++ |+#include <cstring>
6 | using namespace std;
|
s860600423
|
p00042
|
C++
|
#include <fstream>
#include <iostream>
#include <string>
#include <stdio>
#include <vector>
using namespace std;
#define READ_BY_TEXT false
vector<string> splitByDelimiter(string target, string delim) {
std::string s = target;
std::string delimiter = delim;
size_t pos = 0;
std::string token;
vector<string> arr;
while ((pos = s.find(delimiter)) != std::string::npos) {
token = s.substr(0, pos);
arr.push_back(token);
s.erase(0, pos + delimiter.length());
}
arr.push_back(s);
return arr;
}
int W, N;
int w[1000], v[1000];
int dp[1000][1000];
//vector<int> lines;
//int max_v, min_w;
int recursive(int i, int j) {
if (dp[i][j] != -1) return dp[i][j];
int ret;
if (i >= N) {
ret = 0;
}
else if (j < w[i]) {
ret = recursive(i+1, j);
}
else {
ret = max(recursive(i+1, j), recursive(i+1, j-w[i])+v[i]);
}
dp[i][j] = ret;
return ret;
}
int calcMinWeight(int i, int j) {
if (i >= N) {
return 0;
}
int m_w = W;
if (dp[i][j] == -1) {
m_w = min(m_w, calcMinWeight(i+1, j));
}
else {
m_w = min(m_w, calcMinWeight(i+1, j-w[i]) + w[i]);
}
return m_w;
}
int main() {
#if READ_BY_TEXT
// Get values from test.txt
std::ifstream ifs("test.txt");
std::string str;
if (ifs.fail())
{
std::cerr << "??±???" << std::endl;
return -1;
}
getline(ifs, str);
vector<string> words = splitByDelimiter(str, " ");
num_d = stoi(words[0]);
num_n = stoi(words[1]);
for (int i=0; i<num_n; i++) {
getline(ifs, str);
lines.push_back(stoi(str));
}
#else
int case_v = 1;
while (true) {
cin >> W;
if (!W) break;
cin >> N;
string input;
for (int i = 0; i < N; i++) {
// getline(cin, input);
cin >> input;
vector<string> words = splitByDelimiter(input, ",");
v[i] = stoi(words[0]);
w[i] = stoi(words[1]);
}
memset(dp, -1, sizeof(dp));
// Solve
int min_w = W;
int max_v = recursive(0, W);
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
// cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl;
if (dp[i][j] == max_v) {
// cout << "i " << i << " j " << j << endl;
min_w = min(min_w, calcMinWeight(i, j));
// min_w = min(j, min_w);
}
}
}
cout << "Case " << case_v << ":" << endl;
cout << max_v << endl;
cout << min_w << endl;
case_v++;
}
// string input;
// getline(cin, input);
// vector<string> words = splitByDelimiter(input, " ");
// num_d = stoi(words[0]);
// num_n = stoi(words[1]);
// string input1;
// for (int i=0; i<num_n; i++) {
// getline(cin, input1);
// lines.push_back(stoi(input1));
// }
#endif
// recursive(0, 0, "");
// cout << result << endl;
// cout << "num_d = " << num_d << " num_n = " << num_n << "\n";
//
// // Check parsed contents
// for (int i = 0; i < lines.size(); i++) {
// cout << "line[" << i << "] " << to_string(lines[i]) << "\n";
// }
return 0;
}
|
a.cc:4:10: fatal error: stdio: No such file or directory
4 | #include <stdio>
| ^~~~~~~
compilation terminated.
|
s948510265
|
p00042
|
C++
|
#include <fstream>
#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
using namespace std;
#define READ_BY_TEXT false
vector<string> splitByDelimiter(string target, string delim) {
std::string s = target;
std::string delimiter = delim;
size_t pos = 0;
std::string token;
vector<string> arr;
while ((pos = s.find(delimiter)) != std::string::npos) {
token = s.substr(0, pos);
arr.push_back(token);
s.erase(0, pos + delimiter.length());
}
arr.push_back(s);
return arr;
}
int W, N;
int w[1000], v[1000];
int dp[1000][1000];
//vector<int> lines;
//int max_v, min_w;
int recursive(int i, int j) {
if (dp[i][j] != -1) return dp[i][j];
int ret;
if (i >= N) {
ret = 0;
}
else if (j < w[i]) {
ret = recursive(i+1, j);
}
else {
ret = max(recursive(i+1, j), recursive(i+1, j-w[i])+v[i]);
}
dp[i][j] = ret;
return ret;
}
int calcMinWeight(int i, int j) {
if (i >= N) {
return 0;
}
int m_w = W;
if (dp[i][j] == -1) {
m_w = min(m_w, calcMinWeight(i+1, j));
}
else {
m_w = min(m_w, calcMinWeight(i+1, j-w[i]) + w[i]);
}
return m_w;
}
int main() {
#if READ_BY_TEXT
// Get values from test.txt
std::ifstream ifs("test.txt");
std::string str;
if (ifs.fail())
{
std::cerr << "??±???" << std::endl;
return -1;
}
getline(ifs, str);
vector<string> words = splitByDelimiter(str, " ");
num_d = stoi(words[0]);
num_n = stoi(words[1]);
for (int i=0; i<num_n; i++) {
getline(ifs, str);
lines.push_back(stoi(str));
}
#else
int case_v = 1;
while (true) {
cin >> W;
if (!W) break;
cin >> N;
string input;
for (int i = 0; i < N; i++) {
// getline(cin, input);
cin >> input;
vector<string> words = splitByDelimiter(input, ",");
v[i] = stoi(words[0]);
w[i] = stoi(words[1]);
}
memset(dp, -1, sizeof(dp));
// Solve
int min_w = W;
int max_v = recursive(0, W);
for (int i = 0; i < N; i++) {
for (int j = 0; j <= W; j++) {
// cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl;
if (dp[i][j] == max_v) {
// cout << "i " << i << " j " << j << endl;
min_w = min(min_w, calcMinWeight(i, j));
// min_w = min(j, min_w);
}
}
}
cout << "Case " << case_v << ":" << endl;
cout << max_v << endl;
cout << min_w << endl;
case_v++;
}
// string input;
// getline(cin, input);
// vector<string> words = splitByDelimiter(input, " ");
// num_d = stoi(words[0]);
// num_n = stoi(words[1]);
// string input1;
// for (int i=0; i<num_n; i++) {
// getline(cin, input1);
// lines.push_back(stoi(input1));
// }
#endif
// recursive(0, 0, "");
// cout << result << endl;
// cout << "num_d = " << num_d << " num_n = " << num_n << "\n";
//
// // Check parsed contents
// for (int i = 0; i < lines.size(); i++) {
// cout << "line[" << i << "] " << to_string(lines[i]) << "\n";
// }
return 0;
}
|
a.cc: In function 'int main()':
a.cc:101:9: error: 'memset' was not declared in this scope
101 | memset(dp, -1, sizeof(dp));
| ^~~~~~
a.cc:6:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
5 | #include <vector>
+++ |+#include <cstring>
6 | using namespace std;
|
s515455173
|
p00042
|
C++
|
#include<iostream>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define max_n 1000
#define max_w 10000
using namespace std;
int N,W;
int dp[max_n][max_w];
int dw[max_n][max_w];
int w[max_n],v[max_n];
int rec(int i,int j){
int res;
if(dp[i][j]!=-1)return dp[i][j];
if(i==N){
res=0;
dw[i][j]=0;
}else if(j<w[i]){
res=rec(i+1,j);
dw[i][j]=dw[i+1][j];
}else{
int r1=rec(i+1,j);
int r2=rec(i+1,j-w[i])+v[i];
if(r1>r2){
res=r1;
dw[i][j]=dw[i+1][j];
}else if(r2>r1){
res=r2;
dw[i][j]=dw[i+1][j-w[i]]+w[i];
}else{
if(dw[i+1][j]>(dw[i+1][j-w[i]]+w[i])){
res=r2;
dw[i][j]=dw[i+1][j-w[i]]+w[i];
}else{
res=r1;
dw[i][j]=dw[i+1][j];
}
}
}
return dp[i][j]=res;
}
int main(){
int p=1;
while(cin>>W,W){
cin>>N;
rep(i,N){
scanf("%d,%d",&v[i],&w[i]);
}
memset(dp,-1,sizeof(dp));
memset(dw,-1,sizeof(dw));
cout<<"Case "<<p<<":"<<endl;
cout<<rec(0,W)<<endl;
cout<<dw[0][W]<<endl;
p++;
/*cout<<"value="<<rec(0,W)<<" cost="<<dw[0][W]<<endl;//????????§??????????????????
cout<<"cost="<<dw[0][W]<<endl;*/
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:52:17: error: 'memset' was not declared in this scope
52 | memset(dp,-1,sizeof(dp));
| ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
2 | #include<cstdio>
+++ |+#include <cstring>
3 | #define loop(i,a,b) for(int i=a;i<b;i++)
|
s859815420
|
p00042
|
C++
|
# include <iostream>
# include <algorithm>
const int MAX_N = 1001;
const int MAX_W = 1001;
int t;
int n, W;
int v[MAX_N], w[MAX_N];
int dp[MAX_N][MAX_W];
int main() {
while (1) {
std::cin >> W;
if (w == 0)
break;
std::cin >> n;
char ch;
for (int i = 1; i <= n; ++i)
std::cin >> v[i] >> ch >> w[i];
std::memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= W; ++j) {
if (w[i] > j)
continue;
dp[i][j] = std::max(dp[i - 1][j - w[i]] + v[i], dp[i][j]);
}
}
int max = 0, maxv;
for (int i = 0; i <= W; ++i) {
if (max < dp[n][i]) {
maxv = i;
max = dp[n][i];
}
}
++t;
std::cout << "Case " << t << ':' << std::endl;
std::cout << max << std::endl << maxv << std::endl;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:22:22: error: 'memset' is not a member of 'std'; did you mean 'wmemset'?
22 | std::memset(dp, 0, sizeof(dp));
| ^~~~~~
| wmemset
|
s934416746
|
p00042
|
C++
|
# include <iostream>
# include <algorithm>
const int MAX_N = 1001;
const int MAX_W = 1001;
int t;
int n, W;
int v[MAX_N], w[MAX_N];
int dp[MAX_N][MAX_W];
int main() {
while (1) {
std::cin >> W;
if (w == 0)
break;
std::cin >> n;
char ch;
for (int i = 1; i <= n; ++i)
std::cin >> v[i] >> ch >> w[i];
std::memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= W; ++j) {
if (w[i] > j)
continue;
dp[i][j] = std::max(dp[i - 1][j - w[i]] + v[i], dp[i][j]);
}
}
int max = 0, maxv;
for (int i = 0; i <= W; ++i) {
if (max < dp[n][i]) {
maxv = i;
max = dp[n][i];
}
}
++t;
std::cout << "Case " << t << ':' << std::endl;
std::cout << max << std::endl << maxv << std::endl;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:22:22: error: 'memset' is not a member of 'std'; did you mean 'wmemset'?
22 | std::memset(dp, 0, sizeof(dp));
| ^~~~~~
| wmemset
|
s395633926
|
p00042
|
C++
|
# include <iostream>
# include <algorithm>
const int MAX_N = 1001;
const int MAX_W = 1001;
int t;
int n, W;
int v[MAX_N], w[MAX_N];
int dp[MAX_N][MAX_W];
int main() {
while (1) {
std::cin >> W;
if (w == 0)
break;
std::cin >> n;
char ch;
for (int i = 1; i <= n; ++i)
std::cin >> v[i] >> ch >> w[i];
std::memset(dp, 0, sizeof(dp));
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= W; ++j) {
if (w[i] > j)
continue;
dp[i][j] = std::max(dp[i - 1][j - w[i]] + v[i], dp[i][j]);
}
}
int max = 0, maxv;
for (int i = 0; i <= W; ++i) {
if (max < dp[n][i]) {
maxv = i;
max = dp[n][i];
}
}
++t;
std::cout << "Case " << t << ':' << std::endl;
std::cout << max << std::endl << maxv << std::endl;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:22:22: error: 'memset' is not a member of 'std'; did you mean 'wmemset'?
22 | std::memset(dp, 0, sizeof(dp));
| ^~~~~~
| wmemset
|
s074843449
|
p00042
|
C++
|
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 28)
template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int W, N;
int tres[1001];
int weig[1001];
int maxW, maxV;
int dp[1001][1001];
void dfs(int weight, int value, int index){
if(can[index] < maxV)return;
if(weight > W)return;
if(dp[weight][index]>value)return;
dp[weight][index] = value;
if(index == N){
if(maxV < value){
maxW = weight;
maxV = value;
}else if(maxV == value){
if(maxW > weight){
maxW = weight;
maxV = value;
}
}
return;
}
if(dp[weight][index+1]<value)dfs(weight, value, index+1);
if(weight+weig[index] > W)return;
if(dp[weight+weig[index]][index+1]<value+tres[index])dfs(weight+weig[index], value+tres[index], index+1);
}
int main(void){
int cnt = 0;
while(cin >> W, W){
cnt++;
cin >> N;
maxW = 0;
maxV = 0;
// fill_n(tres, 1001, 0);
// fill_n(weig, 1001, 0);
fill_n(*dp, 1001*1001, -1);
rep(i,N){
int n, w;
scanf("%d,%d", &n, & w);
tres[i] = n;
weig[i] = w;
if(i==0)can[i]=tres[i];
else can[i] = can[i-1]+tres[i];
}
dfs(0,0,0);
cout << "Case " << cnt << ":" << endl;
cout << maxV << endl << maxW << endl;
}
return 0;
}
int StrToInt(string s){
stringstream ss;
ss << s;
int val;
ss >> val;
return val;
}
string IntToStr(int i){
stringstream ss;
ss << i;
return ss.str();
}
|
a.cc: In function 'void dfs(int, int, int)':
a.cc:42:12: error: 'can' was not declared in this scope; did you mean 'tan'?
42 | if(can[index] < maxV)return;
| ^~~
| tan
a.cc: In function 'int main()':
a.cc:80:21: error: 'can' was not declared in this scope; did you mean 'tan'?
80 | if(i==0)can[i]=tres[i];
| ^~~
| tan
a.cc:81:18: error: 'can' was not declared in this scope; did you mean 'tan'?
81 | else can[i] = can[i-1]+tres[i];
| ^~~
| tan
|
s974084619
|
p00042
|
C++
|
#include <iostream>
#include <cstdio>
#define MAX(A, B) (A) > (B) ? (A) : (B)
using namespace std;
int dp[1001][1001];
int w[1000], v[1000];
int main() {
int N, W;
int c = 0;
memset(dp, 0, sizeof dp);
while (cin >> W, W) {
cin >> N;
for (int i = 0; i < N; i++) {
scanf("%d,%d", &v[i], &w[i]);
}
for (int i = 0; i < N; i++) {
for (int j = W; j >= 0; j--) {
if (j >= w[i])
dp[i+1][j] = MAX(dp[i][j], dp[i][j-w[i]]+v[i]);
else
dp[i+1][j] = dp[i][j];
}
}
while (dp[N][W] == dp[N][W - 1]) W--;
cout << "Case " << ++c << ':' << endl;
cout << dp[N][W] << endl << W << endl;;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:14:9: error: 'memset' was not declared in this scope
14 | memset(dp, 0, sizeof dp);
| ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
2 | #include <cstdio>
+++ |+#include <cstring>
3 |
|
s008733634
|
p00042
|
C++
|
#include<bits/stdc++.h>
using namespace std;
int dp[1001][1001],wait[1001],value[1001];
void Initialization()
{
for(int i=0;i<1001;i++)for(int j=0;j<1001;j++)dp[i][j]=-1;
}
int power(int n)
{
int num=1;
for(int i=1;i<=n;i++)num*=10;
return num;
}
int serch(int i,int j,int n)
{
int num;
if(dp[i][j]>-1)return dp[i][j];
else if(i==n)num=0;
else if(j<wait[i])num=serch(i+1,j,n);
else num=max(serch(i+1,j,n),serch(i+1,j-wait[i],n)+value[i]);
return dp[i][j]=num;
}
int wserch(int i,int va,int ser,int n,int w)
{
int num;
if(i==n)num=w;
else if(ser<va+value[i])num=wserch(i+1,va,ser,n,w);
else if(ser==va+value[i])num=wait[i];
else num=min(wserch(i+1,va,ser,n,w),wserch(i+1,va+value[i],ser,n,w)+wait[i]);
return num;
}
int main()
{
int n,w,point,num=1,wai,wa;
string str;
while(cin>>w&&w!=0){
cin>>n;
for(int i=0;i<n;i++){
cin>>str;
value[i]=0;wait[i]=0;
for(int j=0;;j++){
if(str[j]==','){
for(int k=0;k<j;k++)value[i]+=power(j-k-1)*(str[k]-'0');
point=j;
}
if(str[j]=='\0'){
for(int k=point+1;k<j;k++)wait[i]+=power(j-k-1)*(str[k]-'0');
break;
}
}
}
Initialization();
point=serch(0,w,n);
wai=w;
for(int i=0;i<n;i++){
if(value[i]<point){
wa=wserch(i+1,value[i],point,n,w)+wait[i];
if(wa<wai)wai=wa;
}
else if(value[i]==point&&wai>wa)wai=wa;
}
cout<<"Case "<<num<<":\n"<<point<<endl<<wai<<endl;
now++;
}
}
|
a.cc: In function 'int main()':
a.cc:63:9: error: 'now' was not declared in this scope; did you mean 'pow'?
63 | now++;
| ^~~
| pow
|
s022026820
|
p00042
|
C++
|
#define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;
#define M_N 1000
#define M_W 10000
typedef pair<int, int> ii; //?????????, ?????????
int W, N;
int v[M_N], w[M_N];
int dp[M_N + 1][M_W + 1][2];
//?????????j??\?????¶??????i????????\????????????????????????
ii dfs(int i, int j) {
if (dp[i][j][0] != -1)
return ii(
dp[i][j][0],
dp[i][j][1]
);
if (i == N) {
//?????°??¶?????????????????¨???
return ii(
dp[i][j][0] = 0,
dp[i][j][1] = 0
);
}
else if (j < w[i]) {
//i??????????????????????????¶?????§??\??????????????¨???
return ii(
dp[i][j][0] = dfs(i + 1, j).first,
dp[i][j][1] = dfs(i + 1, j).second
);
}
else {
//???????????\???????????\??????????????§?????????????????????????????§??¨?????????
int a = dfs(i + 1, j).first,
b = dfs(i + 1, j - w[i]).first + v[i];
if (a > b)
return ii(
dp[i][j][0] = a,
dp[i][j][1] = dfs(i + 1, j).second
);
else
return ii(
dp[i][j][0] = b,
dp[i][j][1] = dfs(i + 1, j - w[i]).second + w[i]
);
}
}
int main() {
for (int h = 0; cin >> W, W; h++) {
cin >> N;
memset(dp, -1, sizeof(dp));
for (int i = 0; i < N; i++) {
char c;
cin >> v[i] >> c >> w[i];
}
cout << "Case " << h << ":" << endl;
cout << dfs(0, W).first << endl;
cout << dfs(0, W).second << endl;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:73:17: error: 'memset' was not declared in this scope
73 | memset(dp, -1, sizeof(dp));
| ^~~~~~
a.cc:18:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
17 | #include<queue>
+++ |+#include <cstring>
18 | #include<vector>
|
s419248790
|
p00042
|
C++
|
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>
#include <random>
using namespace std;
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
int caseId = 1;
void solve42(int W) {
cout << "Case " << caseId << ":" << endl;
int N;
cin >> N;
REP(i,N) {
int dp[1001] = {0}; // dp[i]: maxvalue under weight i
int v, w;
scanf("%d,%d", &v, &w);
for(int j = W; j >= w; j--) {
dp[j] = max(dp[j], dp[j-w] + v);
}
}
int value = 0, weight = 0;
REP(i,W) {
if (value < dp[i]) {
value = dp[i];
weight = i;
}
}
cout << value << endl << weight << endl;
}
int main() {
int W;
while (cin >> W, W) {
solve42(W);
caseId++;
}
return 0;
}
|
a.cc: In function 'void solve42(int)':
a.cc:30:21: error: 'dp' was not declared in this scope
30 | if (value < dp[i]) {
| ^~
|
s335262641
|
p00042
|
C++
|
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define scanf scanf_s
int a[10001] = { 0 };
int b[10001] = { 0 };
int w, n, mv, mw;
void solve(int W, int f, int sum) {
f = min(f, n) + 1;
for (int i = f; i < n; i++) {
if (W - b[i] < 1) {
mw = max(w - W, mw);
mv = max(sum, mv);
return;
}
solve(W - b[i], f, sum + a[i]);
}
}
int main() {
int u = 0;
while (cin >> w) {
if (w == 0) break;
cin >> n;
mv = mw = 0; u++;
for (int i = 0; i < n; i++) {
scanf("%d,%d", &a[i], &b[i]);
}
solve(w, -1, 0);
printf("Case %d:\n%d\n%d\n", u, mv, mw);
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:6:15: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
6 | #define scanf scanf_s
| ^~~~~~~
a.cc:31:25: note: in expansion of macro 'scanf'
31 | scanf("%d,%d", &a[i], &b[i]);
| ^~~~~
|
s592469007
|
p00042
|
C++
|
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
class treasure
{
public:
int value, weight;
bool have;
};
treasure tre[1000];
int N,W, VALUE = 0, WEIGHT = 999999;
void calcu()
{
int sum_v = 0, sum_w = 0;
for (int i = 0; i < N; i++)
{
if (tre[i].have == true)
{
sum_v += tre[i].value;
sum_w += tre[i].weight;
}
}
if (sum_v>VALUE)
{
WEIGHT = sum_w;
VALUE = sum_v;
}
else if(sum_v==VALUE && WEIGHT>sum_w)
{
WEIGHT = sum_w;
}
}
void function(int n, int w)//0,W
{
if (n >= N)
{
calcu();
//cout << VALUE << "," << WEIGHT << endl;
}
else if (tre[n].weight > w)
{
tre[n].have=false;
function(n + 1, w);
}
else
{
tre[n].have = true;
function(n + 1, w - tre[n].weight);
tre[n].have = false;
function(n + 1, w);
}
}
int main()
{
int W;
for (int count = 1; cin >> W, W != 0; count++)
{
VALUE = 0;
WEIGHT = 999999;
cin >> N;
for (int i = 0; i < N; i++)
{
scanf_s("%d,%d", &tre[i].value, &tre[i].weight);
}
function(0,W);
cout << "case " << count << ":" << endl;
cout << VALUE << endl;
cout << WEIGHT << endl;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:71:25: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
71 | scanf_s("%d,%d", &tre[i].value, &tre[i].weight);
| ^~~~~~~
| scanf
|
s316107860
|
p00042
|
C++
|
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
using namespace std;
class treasure
{
public:
int value, weight;
bool have;
};
treasure tre[1000];
int N,W, VALUE = 0, WEIGHT = 999999;
void calcu()
{
int sum_v = 0, sum_w = 0;
for (int i = 0; i < N; i++)
{
if (tre[i].have == true)
{
sum_v += tre[i].value;
sum_w += tre[i].weight;
}
}
if (sum_v>VALUE)
{
WEIGHT = sum_w;
VALUE = sum_v;
}
else if(sum_v==VALUE && WEIGHT>sum_w)
{
WEIGHT = sum_w;
}
}
void function(int n, int w)//0,W
{
if (n >= N)
{
calcu();
}
else if (tre[n].weight > w)
{
tre[n].have=false;
function(n + 1, w);
}
else
{
tre[n].have = true;
function(n + 1, w - tre[n].weight);
tre[n].have = false;
function(n + 1, w);
}
}
int main()
{
int W;
for (int count = 1; cin >> W, W != 0; count++)
{
VALUE = 0;
WEIGHT = 999999;
cin >> N;
for (int i = 0; i < N; i++)
{
scanf_s("%d,%d", &tre[i].value, &tre[i].weight);
}
function(0,W);
cout << "case " << count << ":" << endl;
cout << VALUE << endl;
cout << WEIGHT << endl;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:71:25: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
71 | scanf_s("%d,%d", &tre[i].value, &tre[i].weight);
| ^~~~~~~
| scanf
|
s572331216
|
p00042
|
C++
|
#include <iostream>
#include <array>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
#define out(s) cout << (s) << endl;
int dp[1001][1001];
int main()
{
int W, N, cnt = 1;
cin >> W;
while (W!=0)
{
cin >> N;
memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
for (size_t i = 0; i < N; i++)
{
int vi, wi;
scanf("%d,%d", &vi, &wi);
for (size_t n = 0; n <= W; n++)
{
if (dp[i][n] != -1) {
dp[i + 1][n] = max(dp[i][n], dp[i + 1][n]);
dp[i + 1][n + wi] = max(dp[i][n] + vi, dp[i][n]);
}
}
}
int dp_max = dp[N][W];
int index = W;
for (size_t i = W; i > 0; i--)
{
if (dp_max == dp[N][i])index = i;
}
cout << "Case " << cnt << ":" << endl << dp_max << endl << index << endl;
cin >> W;
cnt++;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:19:17: error: 'memset' was not declared in this scope
19 | memset(dp, -1, sizeof(dp));
| ^~~~~~
a.cc:6:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
5 | #include <vector>
+++ |+#include <cstring>
6 | using namespace std;
|
s799092909
|
p00042
|
C++
|
#include <iostream>
#include <array>
#include <string>
#include <tuple>
#include <vector>
#include<stdio.h>
#include<string.h>
using namespace std;
//using ll = long long;
#define out(s) cout << (s) << endl;
int dp[1010][1010];
int main()
{
int W, N;
cin >> W;
vector<tuple<int, int>> anss;
int cnt = 1;
while (W!=0)
{
cin >> N;
memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
for (size_t i = 0; i < N; i++)
{
int vi, wi;
scanf("%d,%d", &vi, &wi);
for (size_t n = 0; n <= W; n++)
{
if (dp[i][n] != -1) {
dp[i + 1][n] = max(dp[i][n], dp[i + 1][n]);
if (n + wi > W)continue;
dp[i + 1][n + wi] = max(dp[i][n] + vi, dp[i][n]);
}
}
}
int dp_max = *max_element(dp[N], dp[N] + W + 1);
int index = 0;
for (size_t i = 0; i < W+1; i++)
{
if (dp_max == dp[N][i]) { index = i; break; }
}
cout << "Case " << cnt << ":" << endl;
cout << dp_max << endl;
cout << index << endl;
cin >> W;
cnt++;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:38:31: error: 'max_element' was not declared in this scope
38 | int dp_max = *max_element(dp[N], dp[N] + W + 1);
| ^~~~~~~~~~~
|
s985705667
|
p00042
|
C++
|
const int MAX_N = 1000; // n????????§???
const int MAX_W = 5000; // W????????§???
// ??\???
int n, W;
int w[MAX_N], v[MAX_N];
// ?????¢??????????????????
// dp[i][j]???i????????\?????????????????????????????????j??\?????????????????????????????¨??????????????????????????§????????¨??????
// -1????????????????±??????§???????????¨?????¨???
int dp[MAX_N + 1][MAX_W + 1];
// i????????\?????????????????????????????????j??\?????????????????????????????¨?????????
// ???????????????????????????????????§??????????????¢??°
int rec_dp(int i, int j) {
if (dp[i][j] != -1) {
// ?????§?????????????????¨??????????????????????????????????????¨
return dp[i][j];
}
int res;
if (i == n) {
// ????????????????????£??????????????¨?????????????????????????????§??????0??§?¢????
res = 0;
} else if (j < w[i]) {
// ???????????????????¶?????????????i?????\????????????????????§?????\?????????????????????????????????
res = rec_dp(i + 1, j);
} else {
// ??????i?????\???????????\??????????????????????????§???????????????????????????????????§?????????????????¶
res = max(
rec_dp(i + 1, j),
rec_dp(i + 1, j - w[i]) + v[i]
);
}
// ?????????????????????????¨???¶??????
return dp[i][j] = res;
}
void solve_dp() {
memset(dp, -1, sizeof(dp)); // ?????¢??????????????????-1??§??????????????\??????for???????????¨??????
// for (int i = 0; i < MAX_N + 1; i++)
// for (int j = 0; j < MAX_W + 1; j++)
// dp[i][j] = -1;
// 0????????\?????§??????W??\????????´?????????????????¨?????????
cout << rec_dp(0, W) << endl;
}
|
a.cc: In function 'int rec_dp(int, int)':
a.cc:29:11: error: 'max' was not declared in this scope
29 | res = max(
| ^~~
a.cc: In function 'void solve_dp()':
a.cc:39:3: error: 'memset' was not declared in this scope
39 | memset(dp, -1, sizeof(dp)); // ?????¢??????????????????-1??§??????????????\??????for???????????¨??????
| ^~~~~~
a.cc:1:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
+++ |+#include <cstring>
1 | const int MAX_N = 1000; // n????????§???
a.cc:45:3: error: 'cout' was not declared in this scope
45 | cout << rec_dp(0, W) << endl;
| ^~~~
a.cc:45:27: error: 'endl' was not declared in this scope
45 | cout << rec_dp(0, W) << endl;
| ^~~~
|
s960514397
|
p00042
|
C++
|
const int MAX_N = 1000; // n????????§???
const int MAX_W = 5000; // W????????§???
// ??\???
int n, W;
int w[MAX_N], v[MAX_N];
// DP????????????
// dp[i][j]???i????????\?????????????????????????????????j??\?????????????????????????????¨??????????????????????????§????????¨??????
int dp[MAX_N + 1][MAX_W + 1];
void solve_dp2() {
for (int j = 0; j <= W; j++) {
dp[n][j] = 0;
}
for (int i = n - 1; i >= 0; i--) {
for (int j = 0; j <= W; j++) {
if (j < w[i])
dp[i][j] = dp[i + 1][j];
else
dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
}
}
cout << dp[0][W] << endl;
}
|
a.cc: In function 'void solve_dp2()':
a.cc:21:20: error: 'max' was not declared in this scope
21 | dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
| ^~~
a.cc:24:3: error: 'cout' was not declared in this scope
24 | cout << dp[0][W] << endl;
| ^~~~
a.cc:24:23: error: 'endl' was not declared in this scope
24 | cout << dp[0][W] << endl;
| ^~~~
|
s412761132
|
p00042
|
C++
|
const int MAX_N = 1000; // n????????§???
const int MAX_W = 5000; // W????????§???
// ??\???
int n, W;
int w[MAX_N], v[MAX_N];
// DP????????????
// dp[i][j]???i????????\?????????????????????????????????j??\?????????????????????????????¨??????????????????????????§????????¨??????
int dp[MAX_N + 1][MAX_W + 1];
void solve_dp2() {
for (int j = 0; j <= W; j++) {
dp[n][j] = 0;
}
for (int i = n - 1; i >= 0; i--) {
for (int j = 0; j <= W; j++) {
if (j < w[i])
dp[i][j] = dp[i + 1][j];
else
dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
}
}
cout << dp[0][W] << endl;
}
|
a.cc: In function 'void solve_dp2()':
a.cc:21:20: error: 'max' was not declared in this scope
21 | dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
| ^~~
a.cc:24:3: error: 'cout' was not declared in this scope
24 | cout << dp[0][W] << endl;
| ^~~~
a.cc:24:23: error: 'endl' was not declared in this scope
24 | cout << dp[0][W] << endl;
| ^~~~
|
s403034545
|
p00042
|
C++
|
const int MAX_N = 1000; // n????????§???
const int MAX_W = 5000; // W????????§???
// ??\???
int n, W;
int w[MAX_N], v[MAX_N];
// DP????????????
// dp[i][j]???i????????\?????????????????????????????????j??\?????????????????????????????¨??????????????????????????§????????¨??????
int dp[MAX_N + 1][MAX_W + 1];
void solve_dp2() {
for (int j = 0; j <= W; j++) {
dp[n][j] = 0;
}
for (int i = n - 1; i >= 0; i--) {
for (int j = 0; j <= W; j++) {
if (j < w[i])
dp[i][j] = dp[i + 1][j];
else
dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
}
}
cout << dp[0][W] << endl;
}
|
a.cc: In function 'void solve_dp2()':
a.cc:21:20: error: 'max' was not declared in this scope
21 | dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
| ^~~
a.cc:24:3: error: 'cout' was not declared in this scope
24 | cout << dp[0][W] << endl;
| ^~~~
a.cc:24:23: error: 'endl' was not declared in this scope
24 | cout << dp[0][W] << endl;
| ^~~~
|
s663771918
|
p00042
|
C++
|
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
using namespace std;
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define INF 1<<25
typedef long long ll;
int dy[8]={1,1,1,0,0,-1,-1,-1};
int dx[8]={-1,0,1,-1,1,-1,0,1};
struct S{
int a,b,c;
};
bool asc(const S& left,const S& right){
return left.c > right.c;
}
int W,N;
int v[1001],w[1001];
int dp[1001][1001];
int main(){
int cnt=1;
while(cin>>W){
if(W==0)break;
cin>>N;
rep(i,N)cin>>v[i]>>w[i];
REP(i,1,N+1){
rep(j,W+1){
if(w[i-1]<=j)
dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
else
dp[i][j]=dp[i-1][j];
}
}
int ans_v=0,ans_w=0;
rep(i,W+1){
if(dp[N][i]>ans_v){
ans_v=dp[N][i];
ans_w=i;
}
}
cout<<"Case "<<cnt<<<<":"<<endl;
cout<<ans_v<<endl;
cout<<ans_w<<endl;
cnt++;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:68:37: error: expected primary-expression before '<<' token
68 | cout<<"Case "<<cnt<<<<":"<<endl;
| ^~
|
s686260068
|
p00042
|
C++
|
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int dp[1001][1001];
int N, W;
int v[1001], w[1001];
int solve(int i, int j) {
if (dp[i][j] != -1)return dp[i][j];
int res;
if (i == N)res = 0;
else if (j < w[i])res = solve(i + 1, j);
else {
res = max(
solve(i + 1, j),
solve(i + 1, j - w[i]) + v[i]
);
}
return dp[i][j] = res;
}
int main() {
int now = 1;
while (1) {
cin >> W;
if (W == 0)break;
cin >> N;
for (int i = 0; i < N; i++) {
scanf_s("%d,%d", v + i, w + i);
}
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= W; j++) {
dp[i][j] = -1;
}
}
solve(0, W);
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= W; j++) {
cout << i << ":" << j<<"=" << dp[i][j] << endl;
}
}
int value = -1; int weight;
for (int i = 0; i <= W;i++) {
if (value < dp[0][i]) {
value = dp[0][i];
weight = i;
}
}
cout << "Case " << now++ << ":" << endl << value << endl << weight-1 << endl;
}
}
|
a.cc: In function 'int main()':
a.cc:32:25: error: 'scanf_s' was not declared in this scope; did you mean 'scanf'?
32 | scanf_s("%d,%d", v + i, w + i);
| ^~~~~~~
| scanf
|
s467779256
|
p00042
|
C++
|
#include<iostream>
using namespace std;
int main(){
int W,N;
int count = 0;
while(cin >> W){
if(W==0) break;
cin >> N;
count++;
int item[W+1];
for(int i=0;i<=W;i++) item[i]
|
a.cc: In function 'int main()':
a.cc:11:34: error: expected ';' at end of input
11 | for(int i=0;i<=W;i++) item[i]
| ^
| ;
a.cc:11:34: error: expected '}' at end of input
a.cc:6:18: note: to match this '{'
6 | while(cin >> W){
| ^
a.cc:11:34: error: expected '}' at end of input
11 | for(int i=0;i<=W;i++) item[i]
| ^
a.cc:3:11: note: to match this '{'
3 | int main(){
| ^
|
s305320390
|
p00042
|
C++
|
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct treasure{
int value;
int weight;
};
bool comp(treasure t1, treasure t2){
if(t1.weight <= t2.weight) return true;
else return false;
}
int main(){
int w;
const int maxw = 10000;
int count = 1;
while(cin >> w){
if(w == 0) break;
int n;
int cost[maxw + 1];
int best[maxw + 1];
for(int i = 0; i <= maxw; i++){
cost[i] = 0;
best[i] = 0;
}
vector<treasure> treasures;
cin >> n;
for(int i = 0; i < n; i++){
treasure t;
char c;
cin >> t.value >> c >> t.weight;
treasures.push_back(t);
}
sort(treasures.begin(), treasures.end(), comp);
for(int j = 0; j < n; j++){
for(int k = 1; k <= w; k++)
if(k >= treasures[j].weight)
if(cost[k] < cost[k - treasures[j].weight] + treasures[j].value)
{
cost[k] = cost[k - treasures[j].weight] + treasures[j].value;
best[k] = j;
}
}
cout << "Case" << " " << count++ << ":" << endl;
cout << total << endl;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:48:17: error: 'total' was not declared in this scope
48 | cout << total << endl;
| ^~~~~
|
s221354571
|
p00042
|
C++
|
//0042 A Thief
//vñFibvTbNâè
#include<iostream>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main(void)
{
const int MAX_WEIGHT = 1000;
const int MAX_OBJECT = 10000;
const int MAX_SCORE = 1000;
struct Obj
{
int w;
int score;
};
struct Cloth
{
int index;
int totalScore;
};
int caseNum = 1;
while(1)
{
//ÇÌd³ÌÆ«àAÅãÉüê½CfbNXA»êÜÅÌ¿lð¶ÝµÈ¢lÉ
int totalScore[MAX_WEIGHT+1] = {0};
int intoIndex[MAX_WEIGHT+1];
memset(intoIndex, 0xffffffff, sizeof(intoIndex)/sizeof(intoIndex[0]));
//\¢Ì¶áfobOÅl©êÈ¢æI
//Cloth total[MAX_WEIGHT+1];
Obj obj[MAX_OBJECT];
int w, n;
int i, j;
char dummy;
cin >> w;
if(w == 0)
break;
cin >> n;
for(i = 0; i < n; i++)
{
cin >> obj[i].score >> dummy >> obj[i].w;
for(j = w-obj[i].w; j >= 1; j--)
{
//·ÅÉ»Ìd³ÜÅÏÜê½à̪ é
if(totalScore[j])
{
//æèæ¢ÂÝûð©
if(totalScore[j+ obj[i].w] < totalScore[j] + obj[i].score)
{
totalScore[j+ obj[i].w] = totalScore[j] + obj[i].score;
intoIndex[j+ obj[i].w] = i;
}
}
}
//ÅÌÍüêÄà¢¢Ìæ
if(totalScore[obj[i].w] < obj[i].score)
{
totalScore[obj[i].w] = obj[i].score;
intoIndex[obj[i].w] = i;
}
}
cout << "Case " << caseNum << ":" << endl;
caseNum++;
//zñÉüÁ½vfÌÅålÆA»ÌCfbNXðT·
int maxScore = 0;
int maxIndex = -1;
for(i = 0; i <= w; i++)
{
if(totalScore[i] && maxScore<totalScore[i])
{
maxScore = totalScore[i];
maxIndex = i;
}
}
//½©vfÍüÁĽH
if(maxIndex >= 0)
{
cout << totalScore[maxIndex] << endl;
//d³aÌvZ
int totalW = 0;
int index = maxIndex;
while(index>0)
{
totalW += obj[ intoIndex[index] ].w;
index -= obj[ intoIndex[index] ].w;
}
cout << totalW << endl;
}
//êÂàüçÈ©Á½H
else
cout << "0" << endl << "0" << endl;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:33:17: error: 'memset' was not declared in this scope
33 | memset(intoIndex, 0xffffffff, sizeof(intoIndex)/sizeof(intoIndex[0]));
| ^~~~~~
a.cc:7:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
6 | #include<algorithm>
+++ |+#include <cstring>
7 | using namespace std;
|
s541133687
|
p00042
|
C++
|
#include<cstdio>
#include<algorithm>
#include<windows.h>
using namespace std;
int W,N,c;
int w[1001],p[1001];
int dp[10001][1000];
int main(void){
while(scanf("%d", &W)&&W){
int ans;
scanf("%d", &N);
for(int i = 1; i <= N; i++){
scanf("%d,%d", &p[i], &w[i]);
}
for(int i = 1; i <= N; i++){
for(int j = 1;j <= W; j++){
if(i-1 < 0 || j-w[i]<0)continue;
dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i]]+p[i]);
}
}
c++;
printf("Case%2d:\n",c);
printf("%d\n",dp[N][W]);
for(int i = 0; i < W; i++){
if(dp[N][W] == dp[N][W-i]){
ans = i;
}
}
printf("%d\n",W-ans);
/*ツ渉可甘コツ可サ*/
for(int i = 0; i < 1001; i++){
w[i] = 0;
p[i] = 0;
}
for(int i = 0; i < 10001; i++){
for(int j = 0; j < 1000; j++){
dp[i][j] = 0;
}
}
}
return 0;
}
|
a.cc:3:9: fatal error: windows.h: No such file or directory
3 | #include<windows.h>
| ^~~~~~~~~~~
compilation terminated.
|
s123806154
|
p00042
|
C++
|
c[2001],w[2001];
dp[1002][2001];
#define max(a,b) a>b?a:b
N,W,r,x;main(o,i,j){
for(;scanf("%d%d",&W,&N),W;printf("Case %d:\n%d\n%d\n",o++,r,x),memset(dp,0,sizeof dp)){
for(r=N;r--;)scanf("%d,%d",c+r,w+r);
for(i=0;i<=N;i++)for(j=0;j<=W;j++){
//if(i)dp[i][j]=max(dp[i][j],dp[i-1][j]);
dp[i+1][j+w[i]]=max(dp[i+1][j+w[i]],dp[i][j]+c[i]);
if(r<dp[i][j])r=dp[i][j],x=j;
}
}
}
|
a.cc:1:1: error: 'c' does not name a type
1 | c[2001],w[2001];
| ^
a.cc:2:1: error: 'dp' does not name a type
2 | dp[1002][2001];
| ^~
a.cc:4:1: error: 'N' does not name a type
4 | N,W,r,x;main(o,i,j){
| ^
a.cc:4:13: error: expected constructor, destructor, or type conversion before '(' token
4 | N,W,r,x;main(o,i,j){
| ^
|
s311448530
|
p00042
|
C++
|
t[9999][9999],j;main(p,W,a,b,c){
for(;scanf("%d",&W),W;printf("Case %d:\n%d\n%d\n",p++,220,49)){
for(scanf("%d",&c);c&&scanf("%d,%d",&b,&a);c--);
}
}
|
a.cc:1:1: error: 't' does not name a type
1 | t[9999][9999],j;main(p,W,a,b,c){
| ^
a.cc:1:21: error: expected constructor, destructor, or type conversion before '(' token
1 | t[9999][9999],j;main(p,W,a,b,c){
| ^
|
s380745708
|
p00042
|
C++
|
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(itr,c) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define MAX 1010
int W,N;
int w[MAX],v[MAX];
ll dp[MAX][MAX];
int main(){
int i,j;
for(;;){
scanf("%d",&W); if(W == 0) break;
scanf("%d",&N);
rep(i,N) scanf("%d,%d",&v[i],&w[i]);
rep(i,MAX) rep(j,MAX) dp[i][j] = 0;
int res;
for(i = 0; i <= N; i++){
for(j = 0; j <= W; j++){
if(j - w[i] < 0) dp[i+1][j] = dp[i][j];
else {
if(dp[i][j] < dp[i][j-w[i]] + v[i]){
dp[i+1][j] = dp[i][j-w[i]] + v[i];
res = j;
}
else dp[i+1][j] = dp[i][j];
}
}
}
printf("%d\n%d\n",dp[N][W],res);
}
return 0;
}
|
a.cc:23:1: error: 'll' does not name a type
23 | ll dp[MAX][MAX];
| ^~
a.cc: In function 'int main()':
a.cc:33:27: error: 'dp' was not declared in this scope
33 | rep(i,MAX) rep(j,MAX) dp[i][j] = 0;
| ^~
a.cc:38:26: error: 'dp' was not declared in this scope
38 | if(j - w[i] < 0) dp[i+1][j] = dp[i][j];
| ^~
a.cc:40:14: error: 'dp' was not declared in this scope
40 | if(dp[i][j] < dp[i][j-w[i]] + v[i]){
| ^~
a.cc:49:23: error: 'dp' was not declared in this scope
49 | printf("%d\n%d\n",dp[N][W],res);
| ^~
|
s684762936
|
p00042
|
C++
|
// DP
#include <iostream>
#include <cstdio>
#include <algorithm>
#define MAX_N 1001
#define MAX_W 1001
using namespace std;
int main(){
int caseNum = 1;
int ans;
int W, n;
int v[MAX_N];
int w[MAX_N];
int dp[MAX_N][MAX_W];
while(cin >> W){
if(W == 0){
break;
}
cin >> n;
for (int i = 0; i < n; i++) {
scanf("%d,%d", &v[i], &w[i]);
}
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++){
for (int j = 0; j <= W; j++){
if(j < w[i]){
dp[i+1][j] = dp[i][j];
} else{
dp[i+1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
}
}
}
// answer
cout << "Case " << caseNum++ << ":" << endl;
for (int i = W; i >= 0; i--) {
if(dp[n][W] != dp[n][i]) {
ans = i+1;
break;
}
}
cout << dp[n][W] << endl;
cout << ans << endl;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:25:17: error: 'memset' was not declared in this scope
25 | memset(dp, 0, sizeof(dp));
| ^~~~~~
a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
4 | #include <algorithm>
+++ |+#include <cstring>
5 | #define MAX_N 1001
|
s487532101
|
p00042
|
C++
|
#include<iostream>
using namespace std;
const int MAX_w = 1000;
const int MAX_v = 10000;
int dp[MAX_w + 1][MAX_v + 1];
int n, wet ;
int w[MAX_w], v[MAX_v];
// i番目以降の品物から重さの和がj以下なるように選んだときの、
// 取りうる価値の総和の最大値を返す関数
int rec(int i, int j) {
int res;
if(dp[i][j] != -1){
return dp[i][j];
}
if (i == n) {
// 品物がもう残っていないときは、価値の和の最大値は0で確定
res = 0;
} else if (j < w[i]) {
// 残りの容量が足りず品物iを入れられないので、入れないパターンだけ処理
// i+1 以降の品物のみを使ったときの最大値をそのままこの場合の最大値にする
res = rec(i + 1, j);
} else {
// 品物iを入れるか入れないか選べるので、両方試して価値の和が大きい方を選ぶ
res = max(
rec(i + 1, j),
rec(i + 1, j - w[i]) + v[i]
);
}
return res;
}
void solve(int ca) {
// 0番目以降で容量W以下の場合の結果を表示する
int wmin;
memset(dp, -1, sizeof(dp));
cout << "Case" << " " << ca << ":" <<endl;
int ans = rec(0, wet) ;
cout << ans << endl;
for (int w = wet -1 ; w>=0 ; w--){
if( ans != rec(0,w)){
wmin = w+1;
break;
}
}
cout << wmin << endl;
}
int main(){
char x;
int ca = 0;
while(1){
ca++;
cin >> wet;
if(wet == 0 ) break;
cin >> n;
for(int i = 0 ; i<n ; i++){
cin >> v[i] >> x >> w[i];
}
solve(ca);
}
return 0;
}
|
a.cc: In function 'void solve(int)':
a.cc:45:3: error: 'memset' was not declared in this scope
45 | memset(dp, -1, sizeof(dp));
| ^~~~~~
a.cc:2:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
1 | #include<iostream>
+++ |+#include <cstring>
2 |
|
s153753687
|
p00042
|
C++
|
#include <iostream>
#include <algorithm>
using namespace std;
int W, N, casenum = 0, ans, wmin;
int v[1000], w[1000];
int dp[1001][1001];
int rec_dp(int, int);
void solve();
int main(){
int i;
char c;
while(1){
cin >> W >> N;
if(W == 0)
break;
casenum++;
for(i = 0; i < N; i++)
cin >> v[i] >> c >> w[i];
memset(dp, -1, sizeof(dp));
ans = rec_dp(0, W);
for(i = 0; i < W; i++){
if(rec_dp(0, i) == ans){
wmin = i;
break;
}
}
solve();
}
return 0;
}
int rec_dp(int i, int j){
if(dp[i][j] != -1)
return dp[i][j];
int res;
if(i == N)
res = 0;
else if(j < w[i])
res = rec_dp(i + 1, j);
else
res = max(rec_dp(i + 1, j), rec_dp(i + 1, j - w[i]) + v[i]);
return dp[i][j] = res;
}
void solve(){
cout << "Case" << " " << casenum << ":" << endl;
cout << ans << endl;
cout << wmin << endl;
}
|
a.cc: In function 'int main()':
a.cc:26:17: error: 'memset' was not declared in this scope
26 | memset(dp, -1, sizeof(dp));
| ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
2 | #include <algorithm>
+++ |+#include <cstring>
3 |
|
s579907504
|
p00042
|
C++
|
#include<iostream>
#include<stdio.h>
int dp[1000][10000];
int W;
int n;
int v[1000], w[1000];
int now = 1;
int main()
{
while( 1 ){
memset( dp, 0, sizeof( dp ) );
scanf( "%d", &W );
if( !W ) break;
scanf( "%d", &n );
for( int i = 0; i < n; i++ ){
scanf( "%d,%d", &v[i], &w[i] );
}
for( int i = 0; i < n; i++ ){
for( int j = 0; j <= W; j++ ){
if( j < w[i] ){
dp[i+1][j] = dp[i][j];
}
else{
dp[i+1][j] = std::max( dp[i][j], dp[i][j-w[i]] + v[i] );
}
}
}
int res = W;
for( int i = W; i >= 0; i-- ){
if( dp[n][i] == dp[n][W] ) res = std::min( res, i );
else break;
}
printf( "Case %d:\n", now );
printf( "%d\n%d\n", dp[n][W], res );
now++;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:13:17: error: 'memset' was not declared in this scope
13 | memset( dp, 0, sizeof( dp ) );
| ^~~~~~
a.cc:2:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
1 | #include<iostream>
+++ |+#include <cstring>
2 | #include<stdio.h>
|
s695931670
|
p00042
|
C++
|
// 他人のを拝借
#include <iostream>#include <algorithm>#include <cassert>#include <cctype>#include <cstdio>#include <math.h>#include <map>#include <queue>#include <string>using namespace std; int W,N,v[1000],w[1000],dp[1001][1001];char c; int main(){ int cn=0; while(cin>>W){ if(W==0)return 0; cn++; cin>>N; for(int i=0;i<N;i++)cin>>v[i]>>c>>w[i]; for(int i=0;i<N;i++){ for(int j=0;j<=W;j++){ if(j<w[i])dp[i+1][j]=dp[i][j]; else dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]); } } int V=dp[N][W],w2=W; while(dp[N][w2]==V)w2--; cout<<"Case "<<cn<<":"<<endl<<dp[N][W]<<endl<<w2+1<<endl; }}
|
a.cc:2:20: warning: extra tokens at end of #include directive
2 | #include <iostream>#include <algorithm>#include <cassert>#include <cctype>#include <cstdio>#include <math.h>#include <map>#include <queue>#include <string>using namespace std; int W,N,v[1000],w[1000],dp[1001][1001];char c; int main(){ int cn=0; while(cin>>W){ if(W==0)return 0; cn++; cin>>N; for(int i=0;i<N;i++)cin>>v[i]>>c>>w[i]; for(int i=0;i<N;i++){ for(int j=0;j<=W;j++){ if(j<w[i])dp[i+1][j]=dp[i][j]; else dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]); } } int V=dp[N][W],w2=W; while(dp[N][w2]==V)w2--; cout<<"Case "<<cn<<":"<<endl<<dp[N][W]<<endl<<w2+1<<endl; }}
| ^
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x17): undefined reference to `main'
collect2: error: ld returned 1 exit status
|
s482040905
|
p00042
|
C++
|
#include<iostream>
#include<cstdio>
using namespace std;
int data[1000][2];
int dp[1000][1000];
int n,w;
int solve(){
for(int i=1;i<=n;i++){
for(int j=1;j<=w;j++){
if(j >= data[i][1]){
dp[i][j] = max(dp[i-1][j],dp[i-1][j-data[i][1]]+data[i][0]);
}else{
dp[i][j] =dp[i-1][1];
}
}
}
return dp[n][w];
}
int solve2(){
for(int i=0;i<=w;i++){
if(dp[n][w] == dp[n][i]){
return i;
}
}
return w;
}
int main(){
int casecount = 0;
while(true){
casecount++;
cin>>w;
if(w == 0){
break;
}
memset(dp,0,sizeof(dp));
cin >> n;
for(int i=0;i<n;i++){
scanf("%d,%d",&data[i][0],&data[i][1]);
}
cout << "Case " << casecount << ":" << endl;
cout << solve() << endl;
cout << solve2() << endl;
}
}
|
a.cc: In function 'int solve()':
a.cc:12:33: error: reference to 'data' is ambiguous
12 | if(j >= data[i][1]){
| ^~~~
In file included from /usr/include/c++/14/string:53,
from /usr/include/c++/14/bits/locale_classes.h:40,
from /usr/include/c++/14/bits/ios_base.h:41,
from /usr/include/c++/14/ios:44,
from /usr/include/c++/14/ostream:40,
from /usr/include/c++/14/iostream:41,
from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:5:5: note: 'int data [1000][2]'
5 | int data[1000][2];
| ^~~~
a.cc:13:69: error: reference to 'data' is ambiguous
13 | dp[i][j] = max(dp[i-1][j],dp[i-1][j-data[i][1]]+data[i][0]);
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:5:5: note: 'int data [1000][2]'
5 | int data[1000][2];
| ^~~~
a.cc:13:81: error: reference to 'data' is ambiguous
13 | dp[i][j] = max(dp[i-1][j],dp[i-1][j-data[i][1]]+data[i][0]);
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:5:5: note: 'int data [1000][2]'
5 | int data[1000][2];
| ^~~~
a.cc: In function 'int main()':
a.cc:39:17: error: 'memset' was not declared in this scope
39 | memset(dp,0,sizeof(dp));
| ^~~~~~
a.cc:3:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
2 | #include<cstdio>
+++ |+#include <cstring>
3 | using namespace std;
a.cc:43:40: error: reference to 'data' is ambiguous
43 | scanf("%d,%d",&data[i][0],&data[i][1]);
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:5:5: note: 'int data [1000][2]'
5 | int data[1000][2];
| ^~~~
a.cc:43:52: error: reference to 'data' is ambiguous
43 | scanf("%d,%d",&data[i][0],&data[i][1]);
| ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
344 | data(initializer_list<_Tp> __il) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note: 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
334 | data(_Tp (&__array)[_Nm]) noexcept
| ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
323 | data(const _Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note: 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
312 | data(_Container& __cont) noexcept(noexcept(__cont.data()))
| ^~~~
a.cc:5:5: note: 'int data [1000][2]'
5 | int data[1000][2];
| ^~~~
|
s127003667
|
p00042
|
C++
|
#include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <stdio.h>
#include <ctype.h>
#include <algorithm>
#include <stdlib.h>
#include <stack>
#include <queue>
#include <bitset>
using namespace std;
int main() {
int size;
int case_count = 1;
while(cin>>size){
//size==0なら終了
if(size==0){
break;
}
//データの入力
int num;
cin>>num;
int val[num];
int wei[num];
for(int i=0; i<num; i++)scanf("%d,%d",&val[i],&wei[i]);
//計算
int dp[size+1];
int dp_temp[size+1];
int dp_val[size+1];
for(int i=0; i<=size; i++){
dp[i]=0;
dp_val[i]=0;
}
dp[0]=1;
for(int i=0; i<num; i++){
memcpy(dp_temp,dp,sizeof(dp));
for(int j=0; j<=size; j++){
if(dp[j]==1){
int next_wei=j+wei[i];
int next_val=dp_val[j]+val[i];
if(next_wei<=size){
if(dp_val[next_wei]<next_val){
dp_temp[next_wei]=1;
dp_val[next_wei]=next_val;
}
}
}
}
memcpy(dp,dp_temp,sizeof(dp_temp));
}
int max_val=0;
int min_wei=0;
for(int i=0; i<=size; i++){
if(max_val<dp_val[i]){
max_val=dp_val[i];
min_wei=i;
}
}
cout<<"Case "<<case_count<<":"<<endl;
cout<<max_val<<endl;
cout<<min_wei<<endl;
case_count++;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:44:13: error: 'memcpy' was not declared in this scope
44 | memcpy(dp_temp,dp,sizeof(dp));
| ^~~~~~
a.cc:12:1: note: 'memcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
11 | #include <bitset>
+++ |+#include <cstring>
12 |
|
s661111367
|
p00042
|
C++
|
import java.lang.*;
import java.util.*;
public class Main
{
static Scanner sc = new Scanner(System.in);
public static void main(String args[])
{
for(int k=1; ;k++){
int W = sc.nextInt();
if(W==0)break;
int n = sc.nextInt();
int[] dp = new int[W+1];
for(int i=0; i<W; i++){
dp[i]=0;
}
int dv,dw;
for(int i=0; i<n; i++){
String[] s = sc.next().split(",");
dv = Integer.parseInt(s[0]); //value
dw = Integer.parseInt(s[1]); //weight
for(int j=W; j>=0; j--){
if(j == dw) dp[j]=Math.max(dp[j], dv);
else if(dp[j] != 0 && j+dw <= W) dp[j+dw]=Math.max(dp[j+dw], dv+dp[j]);
}
}
int[] max = new int[2];
max[0] = -1; //[0]dv [1]i
for(int i=W; i>0; i--){
if(max[0] <= dp[i]){
max[0] = dp[i];
max[1] = i;
}
}
System.out.println("Case " + k + ":\n" + max[0] +"\n" + max[1]);
}
}
}
|
a.cc:1:1: error: 'import' does not name a type
1 | import java.lang.*;
| ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
2 | import java.util.*;
| ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: expected unqualified-id before 'public'
4 | public class Main
| ^~~~~~
|
s087331827
|
p00042
|
C++
|
// dpの練習
// dpでなく、愚直に組んだプログラミング
// ナップサック問題とほぼ同じ
#include <iostream>
#include <algorithm>
using namespace std;
int wei; // 持てる最大の重さ
int n; // お宝の数
int v[1001]; // お宝の価値
int w[1001]; // お宝の重さ
// グローバル配列は0で初期化されている
int dp[1001][1001]; //メモテーブル
int max_value(int i, int j) {
int value;
if( dp[i][j] >= 0 ){
return dp[i][j];
//すでに1回は調べている
}
if (i == n) {
// 品物がもう残っていないときは、価値の和の最大値は0で確定
//もうお宝がないつまり、価値は0
value = 0;
} else if (j < w[i]) {
//風呂敷が持てる重さを超えてしまう
// 残りの容量が足りず品物iを入れられないので、入れないパターンだけ処理
// i+1 以降の品物のみを使ったときの最大値をそのままこの場合の最大値にする
value = max_value(i + 1, j);
} else {
//左がお宝を入れない、右がお宝を入れた場合
// 品物iを入れるか入れないか選べるので、両方試して価値の和が大きい方を選ぶ
value = max( max_value(i + 1, j), max_value(i + 1, j - w[i]) + v[i] );
}
return dp[i][j] = value;
//メモに記憶させる
}
void max_weight( int ans ){
int w_min;
for (int i = wei -1 ; i >= 0 ; i--){
if( ans != max_value( 0 , i ) ){
w_min = i + 1;
break;
}
}
cout << w_min << endl;
}
int main(void){
int cnt = 1;
while( cin >> wei ){
memset( dp , -1 , sizeof(dp) );
//まだ調べてないところを-1で初期化
if( wei == 0 )break;
cin >> n;
char ten;
for( int i = 0 ; i < n ; i++ ){
cin >> v[i] >> ten >> w[i];
}
cout << "Case " << cnt << ":" << endl;
int ans = max_value( 0 , wei );
cout << ans << endl;
max_weight(ans);
cnt++;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:62:5: error: 'memset' was not declared in this scope
62 | memset( dp , -1 , sizeof(dp) );
| ^~~~~~
a.cc:8:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
7 | #include <algorithm>
+++ |+#include <cstring>
8 |
|
s485368195
|
p00042
|
C++
|
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> obj;
int main(){
int N, W, weight, value;
char ch;
int case_num = 1;
while(1){
cin >> W;
if(W == 0) break;
cin >> N;
//printf("W = %d N = %d\n", W, N);
vector<obj> obj_list;
int dp[2][1010];
memset(dp, -1, sizeof(dp));
for(int i = 0; i < N; i++){
cin >> value >> ch >> weight;
obj_list.push_back(obj(value, weight));
//printf("value = %d weight = %d\n", value, weight);
}
dp[0][0] = 0;
dp[1][0] = 0;
for(int i = 0; i < N; i++){
obj o = obj_list[i];
for(int j = 0; j <= W; j++){
if(dp[(i+1)%2][j] != -1 && j + o.second <= W){
dp[i%2][j+o.second] = max(dp[i%2][j+o.second], dp[(i+1)%2][j] + o.first);
}
}
}
int answer = 0;
int answer_weight = 0;
for(int i = 0; i <= W; i++){
if(answer < dp[(N+1)%2][i]){
answer = dp[(N+1)%2][i];
answer_weight = i;
}
}
cout << "Case " << case_num << ":" << endl;
cout << answer << endl;
cout << answer_weight << endl;
case_num++;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:23:5: error: 'memset' was not declared in this scope
23 | memset(dp, -1, sizeof(dp));
| ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
3 | #include <algorithm>
+++ |+#include <cstring>
4 |
|
s237169142
|
p00042
|
C++
|
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
using namespace std;
int N,W;
struct Treasurea
{
int value;
int weight;
int flag;
Treasurea()
{
value = 0;
weight = 0;
flag = false;
}
};
struct Memo
{
Treasurea record;
bool flag;
Memo()
{
flag = false;
}
};
Memo memo[1001][1001];
Treasurea knapsack(vector<Treasurea> &treasurea, int correntWeight, int correntValue, int step)
{
/*
if(correntWeight < 0)
{
Treasurea temp;
temp.value = correntValue - treasurea[step- 1].value;
temp.weight = W - (correntWeight + treasurea[step- 1].weight);
return temp;
}
*/
if(treasurea.size() == step)
{
Treasurea temp;
temp.value = correntValue;
temp.weight = W - correntWeight;
return temp;
}
else if(memo[correntWeight][step].flag) return memo[correntWeight][step].record;
Treasurea total;
for(int i = 0; i < N; ++i)
{
if(treasurea[i].flag) continue;
treasurea[i].flag = true;
Treasurea temp;
if(correntWeight - treasurea[i].weight >= 0) temp = knapsack(treasurea,correntWeight - treasurea[i].weight, correntValue + treasurea[i].value, step + 1);
else
{
temp.value = correntValue;
temp.weight = W - correntWeight;
}
if( (total.value < temp.value) || (total.value == temp.value && total.weight > temp.weight)) total = temp;
treasurea[i].flag = false;
}
memo[correntWeight][step].record = total;
memo[correntWeight][step].flag = true;
return total;
}
int main()
{
int case_count = 0;
while(cin >> W && W != 0)
{
cin >> N;
vector<Treasurea> treasurea(N);
Treasurea result;
for(int i = 0; i < N; ++i) scanf("%d,%d",&treasurea[i].value,&treasurea[i].weight);
result = knapsack(treasurea,W,0,0);
memset(memo,0,sizeof(memo));
cout << "Case " << ++case_count << ":" << endl << result.value << endl << result.weight << endl;
treasurea.clear();
}
}
|
a.cc: In function 'int main()':
a.cc:117:17: error: 'memset' was not declared in this scope
117 | memset(memo,0,sizeof(memo));
| ^~~~~~
a.cc:5:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
4 | #include<vector>
+++ |+#include <cstring>
5 |
|
s634791542
|
p00042
|
C++
|
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int dp[1001][1001];
int main()
{
int c = 1;
while(1)
{
memset(dp, 0, sizeof(dp));
int w, n;
cin>>w>>n;
if(w == 0)break;
int treasure[1000];
int price[1000];
for(int i = 0; i < n; i++)
scanf("%d,%d", &price[i], &treasure[i]);
for(int i = 0; i < n; i++){
for(int j = 0; j <= w; j++){
if(j < treasure[i])
dp[i + 1][j] = dp[i][j];
else
dp[i + 1][j] = max(dp[i][j], dp[i][j - treasure[i]] + price[i]);
}
}
int ansWeight;
for(ansWeight = w - 1; w >= 0; ansWeight--)
if(dp[n][w] > dp[n][ansWeight])break;
cout << "Case" << c++ <<":"<<endl;
cout << dp[n][w] << endl;
cout << ansWeight + 1 << endl;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:15:17: error: 'memset' was not declared in this scope
15 | memset(dp, 0, sizeof(dp));
| ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
3 | #include<cstdio>
+++ |+#include <cstring>
4 | using namespace std;
|
s149157744
|
p00042
|
C++
|
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std;
struct Treasure
{
int value;
int weight;
Treasure()
{
value = 0;
weight = 0;
}
void operator()( Treasure t)
{
cout << t.value << "," << t.weight << endl;
}
Treasure& operator+=(const Treasure& t )
{
this->value += t.value;
this->weight += t.weight;
return *this;
}
Treasure operator+(const Treasure& t)
{
Treasure tmp;
tmp.value = this->value + t.value;
tmp.weight = this->weight + t.weight;
return tmp;
}
Treasure operator-(const Treasure& t)
{
Treasure tmp;
tmp.value = this->value - t.value;
tmp.weight = this->weight - t.weight;
return tmp;
}
};
Treasure& max(Treasure& t1,Treasure& t2)
{
if(t1.value == t2.value)
{
return (t1.weight < t2.weight) ? t1 : t2;
}
else
{
return (t1.value > t2.value) ? t1 : t2;
}
}
int N,W;
Treasure memo[1000][1000];
Treasure tmp;
vector<Treasure> treasure(1000);
Treasure& Knapsack(int& currentWeight,int& currentCount)
{
Treasure t1,t2,f;
if(memo[currentWeight][currentCount].weight)
{
return memo[currentWeight][currentCount];
}
else if(N == currentCount)
{
return tmp;
}
else{
t1 = Knapsack(currentWeight,currentCount + 1);
if( W >= currentWeight + treasure[currentCount].weight)
{
t2 = Knapsack(currentWeight + treasure[currentCount].weight,currentCount + 1) + treasure[currentCount];
}
else
{
t2 = Knapsack(currentWeight,currentCount + 1);
}
memo[currentWeight][currentCount] = max(t1,t2);
return max(t1,t2);
}
}
int main()
{
int caseNumber = 0;
while(cin >> W && W != 0)
{
cin >> N;
for(int i = 0; i < N; ++i)
{ scanf("%d,%d",&treasure[i].value,&treasure[i].weight); }
Treasure result = Knapsack(0,0);
memset(memo,0,sizeof(memo));
treasure.erase(treasure.begin(),treasure.end());
cout << "Case " << ++caseNumber << ":" << endl;
cout << result.value << endl << result.weight << endl;
}
return 0;
}
|
a.cc: In function 'Treasure& Knapsack(int&, int&)':
a.cc:93:46: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
93 | t1 = Knapsack(currentWeight,currentCount + 1);
| ~~~~~~~~~~~~~^~~
a.cc:78:44: note: initializing argument 2 of 'Treasure& Knapsack(int&, int&)'
78 | Treasure& Knapsack(int& currentWeight,int& currentCount)
| ~~~~~^~~~~~~~~~~~
a.cc:97:37: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
97 | t2 = Knapsack(currentWeight + treasure[currentCount].weight,currentCount + 1) + treasure[currentCount];
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:78:25: note: initializing argument 1 of 'Treasure& Knapsack(int&, int&)'
78 | Treasure& Knapsack(int& currentWeight,int& currentCount)
| ~~~~~^~~~~~~~~~~~~
a.cc:101:50: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
101 | t2 = Knapsack(currentWeight,currentCount + 1);
| ~~~~~~~~~~~~~^~~
a.cc:78:44: note: initializing argument 2 of 'Treasure& Knapsack(int&, int&)'
78 | Treasure& Knapsack(int& currentWeight,int& currentCount)
| ~~~~~^~~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:125:33: error: cannot bind non-const lvalue reference of type 'int&' to an rvalue of type 'int'
125 | Treasure result = Knapsack(0,0);
| ^
a.cc:78:25: note: initializing argument 1 of 'Treasure& Knapsack(int&, int&)'
78 | Treasure& Knapsack(int& currentWeight,int& currentCount)
| ~~~~~^~~~~~~~~~~~~
|
s100256856
|
p00042
|
C++
|
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;
int N;
vector<int> w;
vector<int> v;
int dp[1001][1001];
void solve()
{
int W;
int count = 1;
while(cin >> W, W)
{
memset(dp, 0, sizeof(dp));
cin >> N;
w.resize(N);
v.resize(N);
for(int i = 0; i < N; ++i)
{
scanf("%d,%d", &v[i], &w[i]);
}
for(int i = 0; i < N; ++i)
{
for(int j = 0; j <= W; ++j)
{
if(j < w[i])
{
dp[i + 1][j] = dp[i][j];
}
else
{
dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
}
}
}
int pos = 0;
for(int i = 0; i <= W; ++i)
{
if(dp[N][i] > dp[N][pos])
{
pos = i;
}
}
cout << "Case " << count << ":" << endl;
cout << dp[N][pos] << " " << pos << endl;
++count;
}
}
int main()
{
solve();
return(0);
}
|
a.cc: In function 'void solve()':
a.cc:17:17: error: 'memset' was not declared in this scope
17 | memset(dp, 0, sizeof(dp));
| ^~~~~~
a.cc:4:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
3 | #include <vector>
+++ |+#include <cstring>
4 |
|
s141700826
|
p00042
|
C++
|
#include "math.h"
#include "stdio.h"
#include <algorithm>
#include <string>
#include <vector>
#include <iostream>
using namespace std;
/** Problem0042 : A Thief
Time Limit Exceeded **/
#define MAX_N 1100
#define MAX_W 1100
int W, N, tre[1100][2]={0}, solW, solN;
int dp[MAX_N][MAX_W];
pair<int, int> solve(int i, int j)
{
if (dp[i][j] >= 0)
return pair<int, int>(dp[i][j], j);
pair<int, int> res;
if (i == N) {
res = pair<int, int>(0, W-j);
} else if (j < tre[i][1]) {
res = solve(i+1, j);
} else {
//res.first = max(solve(i+1, j).first, solve(i+1, j-tre[i][1]).first+tre[i][0]);
if (solve(i+1, j).first > solve(i+1, j-tre[i][1]).first+tre[i][0]) {
res = solve(i+1, j);
} else if (solve(i+1, j).first < solve(i+1, j-tre[i][1]).first+tre[i][0]) {
res = pair<int, int>(solve(i+1, j-tre[i][1]).first+tre[i][0], solve(i+1, j-tre[i][1]).second);
} else {
res = pair<int, int>(solve(i+1, j).first, min(solve(i+1, j).second, solve(i+1, j-tre[i][1]).second));
}
}
return res;
}
int main()
{
int set=0; char cam;
while (1) {
set++;
cin >> W;
solW = 0; solN = 0;
if (W==0) break;
cin >> N;
memset(dp, -1, sizeof(dp));
for (int i=0; i<N; i++) {
cin >> tre[i][0] >> cam >> tre[i][1];
}
pair<int, int> sol = solve(0, W);
cout << "Case " << set << ":" << endl;
cout << sol.first << endl;
cout << sol.second << endl;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:55:17: error: 'memset' was not declared in this scope
55 | memset(dp, -1, sizeof(dp));
| ^~~~~~
a.cc:7:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
6 | #include <iostream>
+++ |+#include <cstring>
7 |
|
s155753668
|
p00042
|
C++
|
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;
public class Main {
int INF = 1 << 28;
//long INF = 1L << 62;
double EPS = 1e-10;
void run() {
Scanner sc = new Scanner(System.in);
for (int c=1;;c++) {
int W = sc.nextInt();
if (W == 0) break;
int n = sc.nextInt();
int[] v = new int[n], w = new int[n];
for (int i=0;i<n;i++) {
String[] ws = sc.next().split(",");
v[i] = Integer.valueOf(ws[0]); w[i] = Integer.valueOf(ws[1]);
}
int[] dp = new int[W+1];
fill(dp, -1); dp[0] = 0;
for (int i=0;i<n;i++) for (int j=W;j>=w[i];j--) if (dp[j-w[i]]>=0){
dp[j] = max(dp[j], dp[j-w[i]] + v[i]);
}
int aw = 0, av = 0;
for (int i=0;i<=W;i++) if (av < dp[i]){
av = dp[i];
aw = i;
}
System.out.println("case " + c + ":");
System.out.println(av);
System.out.println(aw);
}
}
void debug(Object... os) {
System.err.println(Arrays.deepToString(os));
}
public static void main(String[] args) {
new Main().run();
}
}
|
a.cc:2:1: error: 'import' does not name a type
2 | import java.util.*;
| ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: 'import' does not name a type
3 | import java.io.*;
| ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: 'import' does not name a type
4 | import static java.util.Arrays.*;
| ^~~~~~
a.cc:4:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: 'import' does not name a type
5 | import static java.util.Collections.*;
| ^~~~~~
a.cc:5:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:6:1: error: 'import' does not name a type
6 | import static java.lang.Math.*;
| ^~~~~~
a.cc:6:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:8:1: error: expected unqualified-id before 'public'
8 | public class Main {
| ^~~~~~
|
s511141261
|
p00042
|
C++
|
#include <iostream>
using namespace std;
int W;
int w[1001],v[1001];
int N;
int dp[1001][1001];
int rec(int i, int j){
//テ」ツつづ」ツ??」ツつ?」ツ?」テ」ツ??
if(dp[i][j] >= 0){
return dp[i][j];
}
int res;
if(i == N){ // テ」ツつづ」ツ??・ツ督?ァツ可ゥテ」ツ?ッテァツ?。テ」ツ??
res = 0;
}else if(j < w[i]){ // テ」ツ?禿」ツ?ョテ・ツ督?ァツ可ゥテ」ツ?ッテ・ツ?・テ」ツつ嘉」ツ?ェテ」ツ??
res = rec(i + 1,j);
}else{ // テ・ツ督?ァツ可ゥテ」ツつ津・ツ環?」ツ?暗」ツつ凝」ツ?禿」ツ?ィテ」ツ?古・ツ?コテヲツ敖・テ」ツつ凝」ツ?ィテ」ツ??
res = max(rec(i+1,j), rec(i+1,j-w[i]) + v[i]);
/*
int tmp1,tmp2;
tmp1 = rec(i+1,j);
tmp2 = rec(i+1,j-w[i]) + v[i];
if(tmp1 < tmp2){
res = tmp2;
}else{
res = tmp1;
}
*/
}
return dp[i][j] = res;
}
int main(){
int num = 1;
while(1){
cin >> W;
if(W == 0) break;
cin >> N;
//テ・ツ按敕ヲツ慊淌・ツ個?
/*
for(int i = 0; i < 1001; i++){
w[i] = v[i] = -1;
for(int j = 0; j < 1001; j++)
dp[i][j] = -1;
}
*/
memset(dp,-1,sizeof(dp));
memset(w,-1,sizeof(w));
memset(v,-1,sizeof(v));
//テ・ツ?・テ・ツ環?
char tmp;
for(int i = 0; i < N; i++) cin >> v[i] >> tmp >> w[i];
int ans = rec(0,W);
// dpテゥツ?催・ツ按療」ツつ津・ツ?ィテ」ツ?ヲテ・ツ淞凝」ツつ?」ツつ?
for(int i = 0; i < N; i++){
for(int j = 0; j <= W; j++){
if(dp[i][j] == -1)
rec(i,j);
}
}
cout << "Case "<< num << ":"<< endl;
num++;
cout << ans << endl;
int j;
for( j = 0; dp[0][j] != ans ; j++){}
cout << j << endl;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:56:5: error: 'memset' was not declared in this scope
56 | memset(dp,-1,sizeof(dp));
| ^~~~~~
a.cc:2:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
1 | #include <iostream>
+++ |+#include <cstring>
2 | using namespace std;
|
s709738572
|
p00042
|
C++
|
#include <iostream>
using namespace std;
int W;
int w[1001],v[1001];
int N;
int dp[1001][1001];
int rec(int i, int j){
//テ」ツつづ」ツ??」ツつ?」ツ?」テ」ツ??
if(dp[i][j] >= 0){
return dp[i][j];
}
int res;
if(i == N){ // テ」ツつづ」ツ??・ツ督?ァツ可ゥテ」ツ?ッテァツ?。テ」ツ??
res = 0;
}else if(j < w[i]){ // テ」ツ?禿」ツ?ョテ・ツ督?ァツ可ゥテ」ツ?ッテ・ツ?・テ」ツつ嘉」ツ?ェテ」ツ??
res = rec(i + 1,j);
}else{ // テ・ツ督?ァツ可ゥテ」ツつ津・ツ環?」ツ?暗」ツつ凝」ツ?禿」ツ?ィテ」ツ?古・ツ?コテヲツ敖・テ」ツつ凝」ツ?ィテ」ツ??
res = max(rec(i+1,j), rec(i+1,j-w[i]) + v[i]);
/*
int tmp1,tmp2;
tmp1 = rec(i+1,j);
tmp2 = rec(i+1,j-w[i]) + v[i];
if(tmp1 < tmp2){
res = tmp2;
}else{
res = tmp1;
}
*/
}
return dp[i][j] = res;
}
int main(){
int num = 1;
while(1){
cin >> W;
if(W == 0) break;
cin >> N;
//テ・ツ按敕ヲツ慊淌・ツ個?
/*
for(int i = 0; i < 1001; i++){
w[i] = v[i] = -1;
for(int j = 0; j < 1001; j++)
dp[i][j] = -1;
}
*/
memset(dp,-1,sizeof(dp));
memset(w,-1,sizeof(w));
memset(v,-1,sizeof(v));
//テ・ツ?・テ・ツ環?
char tmp;
for(int i = 0; i < N; i++) cin >> v[i] >> tmp >> w[i];
int ans = rec(0,W);
// dpテゥツ?催・ツ按療」ツつ津・ツ?ィテ」ツ?ヲテ・ツ淞凝」ツつ?」ツつ?
for(int i = 0; i < N; i++){
for(int j = 0; j <= W; j++){
if(dp[i][j] == -1)
rec(i,j);
}
}
cout << "Case "<< num << ":"<< endl;
num++;
cout << ans << endl;
int j;
for( j = 0; dp[0][j] != ans ; j++){}
cout << j << endl;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:56:5: error: 'memset' was not declared in this scope
56 | memset(dp,-1,sizeof(dp));
| ^~~~~~
a.cc:2:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
1 | #include <iostream>
+++ |+#include <cstring>
2 | using namespace std;
|
s424038362
|
p00042
|
C++
|
#include <iostream>
using namespace std;
int W;
int w[1001],v[1001];
int N;
int dp[1001][1001];
int rec(int i, int j){
//もうやった
if(dp[i][j] >= 0){
return dp[i][j];
}
int res;
if(i == N){ // もう品物は無い
res = 0;
}else if(j < w[i]){ // この品物は入らない
res = rec(i + 1,j);
}else{ // 品物を加えることが出来るとき
res = max(rec(i+1,j), rec(i+1,j-w[i]) + v[i]);
/*
int tmp1,tmp2;
tmp1 = rec(i+1,j);
tmp2 = rec(i+1,j-w[i]) + v[i];
if(tmp1 < tmp2){
res = tmp2;
}else{
res = tmp1;
}
*/
}
return dp[i][j] = res;
}
int main(){
int num = 1;
while(1){
cin >> W;
if(W == 0) break;
cin >> N;
//初期化
/*
for(int i = 0; i < 1001; i++){
w[i] = v[i] = -1;
for(int j = 0; j < 1001; j++)
dp[i][j] = -1;
}
*/
memset(dp,-1,sizeof(dp));
memset(w,-1,sizeof(w));
memset(v,-1,sizeof(v));
//入力
char tmp;
for(int i = 0; i < N; i++) cin >> v[i] >> tmp >> w[i];
int ans = rec(0,W);
// dp配列を全て埋める
for(int i = 0; i < N; i++){
for(int j = 0; j <= W; j++){
if(dp[i][j] == -1)
rec(i,j);
}
}
cout << "Case "<< num << ":"<< endl;
num++;
cout << ans << endl;
int j;
for( j = 0; dp[0][j] != ans ; j++){}
cout << j << endl;
}
return 0;
}
|
a.cc: In function 'int main()':
a.cc:56:5: error: 'memset' was not declared in this scope
56 | memset(dp,-1,sizeof(dp));
| ^~~~~~
a.cc:2:1: note: 'memset' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
1 | #include <iostream>
+++ |+#include <cstring>
2 | using namespace std;
|
s205284317
|
p00043
|
Java
|
import java.io.*;
class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
while((line=br.readLine)!=null){
int n=new int[10];
for(int i=0;i<13;i++){
n[(int)(line.charAt(i)-'1'+1)]++;
}
for(int i=1;i<=9;i++){
if(n[i]<2){
continue;
}
else{
n[i]-=2;
if(check(n)){
System.out.println(i+" ");
}
}
}
System.out.println("");
}
}
private static boolean check(int[] n){
it min=0;
for(int i=1;i<=9;i++){
n[i]%=3;
}
for(int i=1;i<=7;i++){
min=Math.min(n[i],n[i+1]);
min=Math.min(min,n[i+2]);
n[i]-=min;
n[i+1]-=min;
n[i+2]-=min;
}
for(int i=1;i<=9;i++){
if(n[i]!=0){
return false;
}
}
return true;
}
}
|
Main.java:7: error: cannot find symbol
while((line=br.readLine)!=null){
^
symbol: variable readLine
location: variable br of type BufferedReader
Main.java:8: error: incompatible types: int[] cannot be converted to int
int n=new int[10];
^
Main.java:10: error: array required, but int found
n[(int)(line.charAt(i)-'1'+1)]++;
^
Main.java:13: error: array required, but int found
if(n[i]<2){
^
Main.java:17: error: array required, but int found
n[i]-=2;
^
Main.java:18: error: incompatible types: int cannot be converted to int[]
if(check(n)){
^
Main.java:27: error: cannot find symbol
it min=0;
^
symbol: class it
location: class Main
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
7 errors
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.