#include<windows.h>
头文件
DWORD start, end;
声明
start = GetTickCount();
记录开始时间;
在所测程序快前(最好是在你输入结束后,要是只是在main函数里面的话,你一打开黑窗口就开始算时间了)
end = GetTickCount()
记录结束时间
end - start 就是你程序块运行时间,但单位是毫秒,所以还需要除以1000
(double)(end - start)/1000 就是你代码运行的秒数了
上例子
#include<iostream>
#include<windows.h>
using namespace std;
const int MAX=4e3+10;
const int MOD=1e9+7;
const int INF=1e9+7;
typedef long long ll;
int d[2][MAX];
int res[2][MAX];
int a[MAX];
int main()
{
DWORD start, end;
int n,m,w;
cin>>n>>m>>w;
start = GetTickCount();
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
memset(d,0,sizeof d);
for(int i=0;i<=w;i++)res[0][i]=res[1][i]=-INF;
res[0][0]=0;
d[0][0]=-INF;
for(int i=1;i<=n;i++)d[0][i]=a[i];
int now=1,pre=0;
while(m)
{
if(m&1)
{
for(int i=w;i>=0;i--)
{
res[now][i]=-INF;
for(int j=0;j<=i;j++)res[now][i]=max(res[now][i],d[pre][j]+res[pre][i-j]);
}
}
else for(int i=w;i>=0;i--)res[now][i]=res[pre][i];
for(int i=w;i>=0;i--)
{
d[now][i]=-INF;
for(int j=0;j<=i;j++)d[now][i]=max(d[now][i],d[pre][j]+d[pre][i-j]);
}
m/=2;
pre^=1;
now^=1;
}
cout<<res[pre][w]<<endl;
end = GetTickCount() - start;
cout << (double)end/1000 << endl;
return 0;
}