Merge pull request #10 from Kiritow/master

Catch up with you~
This commit is contained in:
KiritoTRw 2016-05-24 15:37:23 +08:00
commit e0fbcbfec4
7 changed files with 320 additions and 0 deletions

2
BZOJ/Readme.md Normal file
View File

@ -0,0 +1,2 @@
#大视野在线测评
[Goto BZOJ Home Page](http://www.lydsy.com/JudgeOnline/ "Welcome to BZOJ")

102
POJ/1170.cpp Normal file
View File

@ -0,0 +1,102 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
/// ItemID[0]=7 stands for "When C=7, This object id is 0"
int ItemID[6];
/// Amount of Item with ID.
int ItemAmount[6];
/// Price of Item with ID.
int ItemPrice[6];
#define MAX_INT 1e9
/// Bucket
int b;
/// Special Combinations.
int s;
///Array of DP
int dp[6][6][6][6][6];
int special_combine[1000][6];
int special_price[1000];
void Solve()
{
/// May be dangerous.
memset(dp,-1,sizeof(dp));
dp[0][0][0][0][0]=0;
/// i,j,k,x,y respects the amount of selected Item, from 0 to 5
for(int i=0;i<=ItemAmount[0];i++)
{
for(int j=0;j<=ItemAmount[1];j++)
{
for(int k=0;k<=ItemAmount[2];k++)
{
for(int x=0;x<=ItemAmount[3];x++)
{
for(int y=0;y<=ItemAmount[4];y++)
{
int FinalPrice = MAX_INT;
int TempPrice = MAX_INT;
/// Try Each Special Combination
for(int si=0;si<s;si++)
{
if(i>=special_combine[si][0]&&j>=special_combine[si][1]&&k>=special_combine[si][2]&&x>=special_combine[si][3]&&y>=special_combine[si][4])
{
TempPrice = dp[i-special_combine[si][0]][j-special_combine[si][1]][k-special_combine[si][2]][x-special_combine[si][3]][y-special_combine[si][4]] +special_price[si];
FinalPrice = min(FinalPrice,TempPrice);
}
}
if(FinalPrice!=MAX_INT)
{
dp[i][j][k][x][y]=FinalPrice;
}
else
{
/// Just Calculate the original price
dp[i][j][k][x][y]=i*ItemPrice[0]+j*ItemPrice[1]+k*ItemPrice[2]+x*ItemPrice[3]+y*ItemPrice[4];
}
}
}
}
}
}
}
int main()
{
scanf("%d",&b);
for(int i=0;i<b;i++)
{
scanf("%d %d %d",&ItemID[i],&ItemAmount[i],&ItemPrice[i]);
}
scanf("%d",&s);
for(int i=0;i<s;i++)
{
int _tmp;
scanf("%d",&_tmp);
for(int j=0;j<_tmp;j++)
{
int a,b;
scanf("%d %d",&a,&b);
/// Get Original ID to Hashed ID.
for(int k=0;k<6;k++)
{
if(ItemID[k]==a)
{
special_combine[i][k]=b;
break;
}
}
}
scanf("%d",&special_price[i]);
}
Solve();
printf("%d\n",dp[ItemAmount[0]][ItemAmount[1]][ItemAmount[2]][ItemAmount[3]][ItemAmount[4]]);
return 0;
}

61
QUSTOJ/1292_ysh.cpp Normal file
View File

@ -0,0 +1,61 @@
#include <stdio.h>
#define sample scanf("%d", &b);
#define hahaha printf("/\\ /\\\n _");
#define outspace printf(" ");
#define bigchange printf("\n");
int main()
{
int a;
scanf("%d", &a);
for(int i = 0, b; i < a; i++)
{
sample
if(b == 1)
{
hahaha
}
else
{
printf("\n");
for(int j = 0; j < b; j++)
{
for(int k = 0; k < b-j-1; k++)
{
outspace
}
printf("/");
for(int k = 0; k < j*2; k++)
{
outspace
}
printf("\\");
for(int k = 0; k < b*3-(j+1)*2; k++)
{
outspace
}
printf("/");
for(int k = 0; k < j*2; k++)
{
outspace
}
printf("\\");
bigchange
}
for(int j = 0; j < b-1; j++)
{
bigchange
}
for(int j = 0; j < b*2; j++)
{
outspace
}
for(int j = 0; j < b; j++)
{
printf("_");
}
}
bigchange
}
return 0;
}

35
VIJOS/1313_hzwer.cpp Normal file
View File

@ -0,0 +1,35 @@
#include<iostream>
using namespace std;
int main()
{
int a,b,mx=0;
int i,j;
int m,n,v[61]={0},p[61]={0},q;
int v1[61]={0},v2[61]={0},p1[61]={0},p2[61]={0};
int f[50001]={0};
cin>>m>>n;
m/=10;
for(i=1;i<=n;i++)
{
cin>>a>>b>>q;
a/=10;
if(q!=0)
{
if(v1[q]==0){v1[q]=a;p1[q]=b;}
else {v2[q]=a;p2[q]=b;}
}
else {v[i]=a;p[i]=b;}
}
for(int i=1;i<=n;i++)
for(int j=m;j>=v[i];j--)
{
f[j]=max(f[j],f[j-v[i]]+v[i]*p[i]);
if(j-v1[i]-v[i]>=0)f[j]=max(f[j],f[j-v1[i]-v[i]]+v1[i]*p1[i]+v[i]*p[i]);
if(j-v2[i]-v[i]>=0)f[j]=max(f[j],f[j-v2[i]-v[i]]+v2[i]*p2[i]+v[i]*p[i]);
if(j-v1[i]-v2[i]-v[i]>=0)f[j]=max(f[j],f[j-v1[i]-v2[i]-v[i]]+v1[i]*p1[i]+v2[i]*p2[i]+v[i]*p[i]);
mx=max(f[j],mx);
}
cout<<mx*10;
//system("pause");
return 0;
}

View File

@ -0,0 +1,54 @@
#include <stdio.h>
int numThing[100];
int costs[100][5];
int values[100][5];
int dp[3201];
int MAX(int a, int b){
return a>b ? a:b;
}
int main(){
int limit, num;
int cost, value, index, i, k;
scanf("%d %d", &limit, &num);
limit /= 10;
for(i=0; i<=num; i++)
numThing[i] = 0;
for(i=0; i<num; i++){
scanf("%d %d %d", &cost, &value, &index);
index--;
if(index < 0)
index = i;
costs[index][numThing[index]] = cost/10;
values[index][numThing[index]] = value;
numThing[index]++;
}
for(i=0; i<=limit; i++)
dp[i] = 0;
for(i=0; i<num; i++){
if(numThing[i] == 0)
continue;
for(k=limit; k>=costs[i][0]; k--){
switch(numThing[i]){
case 3:
if(k-costs[i][0]-costs[i][1]-costs[i][2] >= 0)
dp[k] = MAX(dp[k], dp[k-costs[i][0]-costs[i][1]-costs[i][2]] + values[i][0]*costs[i][0] + values[i][1]*costs[i][1] + values[i][2]*costs[i][2]);
case 2:
if(k-costs[i][0]-costs[i][1] >= 0)
dp[k] = MAX(dp[k], dp[k-costs[i][0]-costs[i][1]] + values[i][0]*costs[i][0] + values[i][1]*costs[i][1]);
if(k-costs[i][0]-costs[i][2] >= 0)
dp[k] = MAX(dp[k], dp[k-costs[i][0]-costs[i][2]] + values[i][0]*costs[i][0] + values[i][2]*costs[i][2]);
case 1:
dp[k] = MAX(dp[k], dp[k-costs[i][0]] + values[i][0]*costs[i][0]);
}
}
}
printf("%d\n", dp[limit]*10);
return 0;
}

47
VIJOS/1317.cpp Normal file
View File

@ -0,0 +1,47 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
/// 0-1背包问题(一维数组空间优化)
namespace Package1_SpaceOptimized
{
const int MAXM = 30000 + 5;
const int MAXN = 25 + 5;
int ldp[MAXM];
int w[MAXN];
int v[MAXN];
int N,M;
void solve()
{
for(int i=1;i<=N;i++)
{
for(int j=M;j>=1;j--)///从M到1逆序循环
{
int a=ldp[j];
int b=-1;
if(j-w[i]>=0) b=ldp[j-w[i]]+v[i];
ldp[j]=max(a,b);
}
}
printf("%d\n",ldp[M]);
}
int main()
{
scanf("%d %d",&M,&N);
for(int i=1;i<=N;i++)
{
scanf("%d %d",&w[i],&v[i]);
v[i]=w[i]*v[i];
}
solve();
return 0;
}
}
int main()
{
return Package1_SpaceOptimized::main();
}

19
VIJOS/1317_hzwer.cpp Normal file
View File

@ -0,0 +1,19 @@
#include<iostream>
using namespace std;
int main()
{
int m,n,i,v;
int w[25],c[25],f[30001];
cin>>m>>n;
for(i=1;i<=n;i++)
{
cin>>w[i]>>c[i];
c[i]*=w[i];
}
for(i=1;i<=n;i++)
for(v=m;v>=w[i];v--)
if(f[v]<f[v-w[i]]+c[i])
f[v]=f[v-w[i]]+c[i];
cout<<f[m];
return 0;
}