标签:
2 3 5 -4 3 -6 3 7 0 0
1 2 11
#include <iostream>
#include <cstring>
using namespace std;
int ary[25][25];
int n,m;
int sum;
void fun(int x,int y,int num)
{
if(x < 1 || x > n || y < 1 || y > m)
return ;
if(ary[x][y] * num < 0)
{
sum += abs(ary[x][y]);
}
else
sum -= abs(ary[x][y]);
}
int main()
{
int i,j,k;
int t;
int a,b;
int cnt;
while(~scanf("%d%d",&n,&m),n&&m)
{
memset(ary,0,sizeof(ary));
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
scanf("%d",&ary[i][j]);
}
int maxn = 0;
for(i=1;i<=n;i++)
{
for(j=1;j<=m;j++)
{
sum = 0;
fun(i-1,j,ary[i][j]);
fun(i+1,j,ary[i][j]);
fun(i,j-1,ary[i][j]);
fun(i,j+1,ary[i][j]);
if(sum > maxn)
{
a = i;
b = j;
maxn = sum;
}
}
}
printf("%d %d %d\n",a,b,maxn);
}
return 0;
}
5 1 6 1 4 3 3 0 3 2 2 3 3 3 3 2 1 0 2 4 2 5 0 0 1 0 4 4 1 3 3 4 3 4 4
12 4
#include <iostream>
#include <cstring>
using namespace std;
int dp[105][105][105];
struct node
{
int a,b,w;
}list[105];
inline int max(int a,int b)
{
return a>b?a:b;
}
int main()
{
int i,j,k,kk;
int t;
int a,b;
int cnt;
int n,m,v1,v2;
while(~scanf("%d%d%d%d",&n,&v1,&v2,&kk))
{
for(i=1;i<=n;i++)
scanf("%d%d%d",&list[i].a,&list[i].b,&list[i].w);
memset(dp,0,sizeof(dp));
for(i=1;i<=n;i++)
{
for(t=kk;t>=0;t--)
{
for(j=v1;j>=0;j--)
{
for(k=v2;k>=0;k--)
{
int temp = 0;
if(t>=1)
temp = max(temp,dp[t-1][j][k] + list[i].w);
if(j-list[i].a>=0)
temp = max(temp,dp[t][j-list[i].a][k] + list[i].w);
if(k-list[i].b>=0)
temp = max(temp,dp[t][j][k-list[i].b] + list[i].w);
dp[t][j][k] = max(dp[t][j][k],temp);
}
}
}
}
printf("%d\n",dp[kk][v1][v2]);
}
return 0;
}1 10 5 1 5 100 3 10 10 5 10 100 1 4 2 6 12 266
102
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int dp[105];
struct node
{
int a,b,w;
}list[1105];
inline int max(int a,int b)
{
return a>b?a:b;
}
int cmp(node aa,node bb)
{
if(aa.a == bb.a)
return aa.b < bb.b;
return aa.a < bb.a;
}
int main()
{
int i,j,k,kk;
int N;
int t;
int a,b,w;
int cnt;
int n,m,v1,v2;
scanf("%d",&N);
while(N-- && scanf("%d%d",&m,&n))
{
for(i=1,k=1;i<=n;i++)
{
scanf("%d%d%d",&list[i].a,&list[i].b,&list[i].w);
if(list[i].a > m || list[i].a < 1)
{ i--;n--;}
}
sort(list+1,list+1+n,cmp);
memset(dp,0,sizeof(dp));
for(i=1;i<=n;i++)
{
for(j=m;j>=list[i].b;j--)
{
dp[j] = max(dp[j],dp[list[i].a-1]+list[i].w);
}
}
printf("%d\n",dp[m]);
}
return 0;
}1 5 3 3 3 3 4
0.400
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
int i,j,k,kk;
int N;
int t;
int a,b,w;
int cnt,n;
int ary[1005];
int sum;
scanf("%d",&N);
while(N-- && scanf("%d",&n))
{
for(i=1,sum=0;i<=n;i++)
{
scanf("%d",&ary[i]);
sum += ary[i]*(n-1-ary[i]);
}
sum /= 2;
printf("%.3lf\n",1.0-sum*1.0/((n*(n-1)*(n-2))/6));
}
return 0;
}88 90 50
6 [hint] 样例解析: 当前比分是88:90,还剩50秒则对方还最多有一次进攻机会(最后5秒进攻不成功),我方有两次,对方的最终得分将是91, 我方至少在两回合中拿到4分才能胜利,所以所有方案数是6种,即: 第一球 第二球 1 3 2 2 2 3 3 1 3 2 3 3 [/hint]
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
<span style="white-space:pre"> </span>int i,j,k,kk;
<span style="white-space:pre"> </span>int N;
<span style="white-space:pre"> </span>int a,b,t;
<span style="white-space:pre"> </span>int cnt,n;
<span style="white-space:pre"> </span>__int64 sum;
<span style="white-space:pre"> </span>int dp[50][150];
<span style="white-space:pre"> </span>memset(dp,0,sizeof(dp));
<span style="white-space:pre"> </span>dp[0][0]=dp[1][1]=dp[1][2]=dp[1][3]=1;
<span style="white-space:pre"> </span>for(i=2;i<=45;i++)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>for(j=0;j<=200;j++)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>dp[i][j] = dp[i-1][j-1]+dp[i-1][j-2]+dp[i-1][j-3];
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>while(~scanf("%d%d%d",&a,&b,&t))
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>int ha = t/15 - t/30;
<span style="white-space:pre"> </span>b += t/30;
<span style="white-space:pre"> </span>int score = b-a+1>0?(b-a+1):0;
<span style="white-space:pre"> </span>for(i=score,sum=0;i<=ha*3;i++)
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>sum += dp[ha][i];
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>printf("%I64d\n",sum);
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>return 0;
}
2013腾讯编程马拉松初赛第〇场(3月20日)(HDU 4500 4501 4502 4503 4504)
标签:
原文地址:http://blog.csdn.net/xinwen1995/article/details/51235736